forked from bk192077/struct_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.cpp
More file actions
36 lines (28 loc) · 655 Bytes
/
person.cpp
File metadata and controls
36 lines (28 loc) · 655 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
#include "struct_mapping/struct_mapping.h"
#include <iostream>
#include <sstream>
#include <string>
struct Person
{
std::string name;
int age;
bool student;
};
int main()
{
struct_mapping::reg(&Person::name, "name");
struct_mapping::reg(&Person::age, "age");
struct_mapping::reg(&Person::student, "student");
Person person;
std::istringstream json_data(R"json(
{
"name": "Jeebs",
"age": 42,
"student": true
}
)json");
struct_mapping::map_json_to_struct(person, json_data);
std::ostringstream out_json_data;
struct_mapping::map_struct_to_json(person, out_json_data, " ");
std::cout << out_json_data.str() << std::endl;
}