Skip to content

Commit 64e69f1

Browse files
Fix types
1 parent cfb38f2 commit 64e69f1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

examples/warehouse/types.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@
22
#include <nlohmann/json.hpp>
33

44
enum class category { order, cash_carry };
5+
56
struct Product {
7+
Product() :
8+
id(),
9+
price(),
10+
name(),
11+
cat(order) {}
12+
613
std::string id;
714
double price;
815
std::string name;
916
category cat;
1017
};
1118

12-
NLOHMANN_JSON_SERIALIZE_ENUM(category, {{category::order, "order"}, {category::cash_carry, "cc"}});
13-
inline void to_json(nlohmann::json &j, const Product &p) { j = nlohmann::json{{"id", p.id}, {"price", p.price}, {"name", p.name}, {"category", p.cat}}; }
19+
NLOHMANN_JSON_SERIALIZE_ENUM(category, {{category::order, "order"}, {category::cash_carry, "cc"}})
20+
21+
inline void to_json(nlohmann::json &j, const Product &p) {
22+
j = nlohmann::json{{"id", p.id},
23+
{"price", p.price},
24+
{"name", p.name},
25+
{"category", p.cat}};
26+
}
27+
1428
inline void from_json(const nlohmann::json &j, Product &p) {
1529
j.at("name").get_to(p.name);
1630
j.at("id").get_to(p.id);
1731
j.at("price").get_to(p.price);
1832
j.at("category").get_to(p.cat);
19-
}
33+
}

0 commit comments

Comments
 (0)