forked from bk192077/struct_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.cpp
More file actions
42 lines (32 loc) · 700 Bytes
/
struct.cpp
File metadata and controls
42 lines (32 loc) · 700 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
41
42
#include "struct_mapping/struct_mapping.h"
#include <iostream>
#include <sstream>
#include <string>
struct President
{
std::string name;
double mass;
};
struct Earth
{
President president;
};
int main()
{
struct_mapping::reg(&President::name, "name");
struct_mapping::reg(&President::mass, "mass");
struct_mapping::reg(&Earth::president, "president");
Earth earth;
std::istringstream json_data(R"json(
{
"president": {
"name": "Agent K",
"mass": 75.6
}
}
)json");
struct_mapping::map_json_to_struct(earth, json_data);
std::ostringstream out_json_data;
struct_mapping::map_struct_to_json(earth, out_json_data, " ");
std::cout << out_json_data.str() << std::endl;
}