-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.cpp
144 lines (124 loc) · 2.93 KB
/
app.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "json_reflect.hpp"
auto json1 = R"({
"MixedArray": [
"one",
50,
false,
12.005
],
"People": [
null,
{
"name": "qwer",
"age": 1000,
"sex": true,
"flow": 3.000
},
{
"name": "qq849635649",
"age": 10,
"sex": null
},
{
"name": null,
"age": 20,
"sex": true,
"zzzz": "11"
}
]
})";
struct e1 {
std::optional<std::string> name;
int age;
bool sex;
float flow;
REFLECT_INTRUSIVE(e1, name, age, sex, flow);
};
struct e2 {
std::string name;
int age;
std::optional<bool> sex;
REFLECT_INTRUSIVE(e2, name, age, sex);
};
struct e3 {
std::optional<std::string> name;
int age;
bool sex;
std::string zzzz;
REFLECT_INTRUSIVE(e3, name, age, sex, zzzz);
};
struct sjson1 {
std::tuple<std::string, int, bool, float> MixedArray;
std::tuple<std::optional<e2>, std::optional<e1>, e2, e3> People;
REFLECT_INTRUSIVE(sjson1, MixedArray, People);
};
auto json_str = R"(
{
"pi": 3.141,
"happy": true,
"name": "Niels",
"answer": {
"everything": 42
},
"list": [7, 8, 9, 9 ],
"object": {
"currency": "USD",
"value": 42.99
},
"map":{
"key1": [{"currency": "USD","value" : 40.99},{"currency": "USD","value" : 41.99,"yes" : true},{"currency": "USD","value" : 42.99}],
"key2": [{"currency": "USD","value" : 43.99},{"currency": "USD","value" : 44.99,"yes" : true},{"currency": "USD","value" : 45.99}]
},
"taowa":{
"keyzz": {
"wa":{
"zz":"zz"
}
}
}
})";
struct obj {
std::optional<std::string> currency;
float value;
};
REFLECT_NON_INTRUSIVE(obj, currency, value);
struct zzz {
std::string zz;
};
REFLECT_NON_INTRUSIVE(zzz, zz);
struct obj1 {
std::string currency;
float value;
bool yes;
};
REFLECT_NON_INTRUSIVE(obj1, currency, value, yes);
struct keymap {
std::tuple<obj, obj1, obj> key1;
std::tuple<obj, obj1, obj> key2;
};
REFLECT_NON_INTRUSIVE(keymap, key1, key2);
struct json_struct {
std::optional<std::string> nothing;
std::string name;
bool happy;
float pi;
std::unordered_map <std::string, int> answer;
std::vector<int> list;
obj object;
keymap map;
std::unordered_map<std::string, std::map<std::string, zzz>> taowa;
};
REFLECT_NON_INTRUSIVE(json_struct, nothing, name, happy, pi, answer, list, object, map, taowa);
struct test_struct {
std::optional<std::string> f;
REFLECT_INTRUSIVE(test_struct, f);
};
int main() {
auto json1_data = jreflect::from_json<sjson1>(json1);
auto json1_str = jreflect::to_json(json1_data);
auto j_data = jreflect::from_json<json_struct>(json_str);
auto j_str = jreflect::to_json(j_data);
test_struct ts{ "3445988958568569586565446e5yeyrtyru" };
auto test_struct_str = jreflect::to_json(std::move(ts));
return 0;
}