-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathprint.cpp
More file actions
40 lines (33 loc) · 1013 Bytes
/
print.cpp
File metadata and controls
40 lines (33 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <serdepp/serde.hpp>
#include <serdepp/adaptor/nlohmann_json.hpp>
struct Object {
DERIVE_SERDE(Object,
(&Self::radius, "radius")
(&Self::width, "width")
(&Self::height, "height"))
std::optional<int> radius;
std::optional<int> width;
std::optional<int> height;
};
struct Test {
DERIVE_SERDE(Test,
(&Self::type, "type")
[attributes(flatten)]
(&Self::object, "object"))
std::string type;
Object object;
};
int main(int argc, char *argv[])
{
nlohmann::json jflat = R"([
{"type": "circle", "radius": 5},
{"type": "rectangle", "width": 6, "height": 5}
])"_json;
nlohmann::json j = R"([
{"type": "circle", "object": {"radius" : 5}},
{"type": "rectangle", "object": {"width": 6, "height": 5}}
])"_json;
auto j_flatten = serde::deserialize<std::vector<Test>>(jflat);
std::cout << serde::to_string(j_flatten) << "\n";
return 0;
}