![]() |
DAW JSON Link
|
Arbitrary C++ data structures are supported and can be described using the trait json_data_contract
.
Below is an ordinary JSON object
The above JSON describes a class with three members, a string named member0
, an integer named member1
, and a boolean named member2
Below is the C++ data structure and the trait to map the members to that of the JSON object. Note that the names of the C++ data members do not have to be the same as the JSON object's. To see a working example using this code, refer to cookbook_class1_test.cpp
The above json_data_contract
trait maps the JSON members to the constructor of MyClass1
in the order specified. The arguments of type std::string, int, bool
will be passed.
The serializing and deserializing is recursive. So if a class contains another class, the requirement is that that class has been mapped already. Assuming we already have the mapping above, lets embed that into another class
The JSON object that has a member "a"
that matches MyClass1
, and a second member is an unsigned
To see a working example using this code, refer to cookbook_class2_test.cpp
Not all of the JSON objects members need to be mapped. Below is the same JSON object as in the MyClass2
example above. To see a working example using this code, refer to cookbook_class3_test.cpp
Only the "a"
member is mapped, the "b"
member of the JSON object is ignored.