diff --git a/README.md b/README.md index 1c95cd6..dec4b37 100644 --- a/README.md +++ b/README.md @@ -79,28 +79,28 @@ The following table shows the mapping of supported C++ types to supported JSON t ## Usage This example shows how the library can be used to make a `struct` serializable:
-#include+#include <reflective_rapidjson/json/serializable.h> // define structures, eg. -struct TestObject : public ReflectiveRapidJSON::JsonSerializable { +struct TestObject : public ReflectiveRapidJSON::JsonSerializable<TestObject> { int number; double number2; - vector numbers; + vector<int> numbers; string text; bool boolean; }; -struct NestingObject : public ReflectiveRapidJSON::JsonSerializable { +struct NestingObject : public ReflectiveRapidJSON::JsonSerializable<NestingObject> { string name; TestObject testObj; }; -struct NestingArray : public ReflectiveRapidJSON::JsonSerializable { +struct NestingArray : public ReflectiveRapidJSON::JsonSerializable<NestingArray> { string name; - vector testObjects; + vector<TestObject> testObjects; }; // serialize to JSON NestingArray obj{ ... }; -cout << "JSON: " << obj.toJson().GetString(); +cout << "JSON: " << obj.toJson().GetString(); // deserialize from JSON const auto obj = NestingArray::fromJson(...); @@ -120,8 +120,8 @@ reflective_rapidjson_generator \ It works very similar to the example above. Just use the `BinarySerializable` class instead (or in addition): -#include#### Invoking code generator with CMake macro @@ -206,34 +206,34 @@ Macro's `CLANG_OPTIONS_FROM_TARGETS` argument. The same example as above. However, this time Boost.Hana is used - so it doesn't require invoking the generator.-struct TestObject : public ReflectiveRapidJSON::BinarySerializable +#include <reflective_rapidjson/binary/serializable.h> +struct TestObject : public ReflectiveRapidJSON::BinarySerializable<TestObject> -#include "The code generator will emit the code in the same way as if `JsonSerializable` was @@ -281,7 +281,7 @@ to enable this by adding `friend` methods for the helper functions of Reflective To make things easier, there's a macro provided:+#include "<reflective_rapidjson/json/serializable-boosthana.h> // define structures using BOOST_HANA_DEFINE_STRUCT, eg. -struct TestObject : public JsonSerializable { +struct TestObject : public JsonSerializable<TestObject> { BOOST_HANA_DEFINE_STRUCT(TestObject, (int, number), (double, number2), - (vector , numbers), + (vector<int>, numbers), (string, text), (bool, boolean) ); }; -struct NestingObject : public JsonSerializable { +struct NestingObject : public JsonSerializable<NestingObject> { BOOST_HANA_DEFINE_STRUCT(NestingObject, (string, name), (TestObject, testObj) ); }; -struct NestingArray : public JsonSerializable { +struct NestingArray : public JsonSerializable<NestingArray> { BOOST_HANA_DEFINE_STRUCT(NestingArray, (string, name), - (vector , testObjects) + (vector<TestObject>, testObjects) ); }; // serialize to JSON NestingArray obj{ ... }; -cout << "JSON: " << obj.toJson().GetString(); +cout << "JSON: " << obj.toJson().GetString(); // deserialize from JSON const auto obj = NestingArray::fromJson(...); @@ -266,7 +266,7 @@ REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(ThridPartyStruct) // (de)serialization ReflectiveRapidJSON::JsonReflector::toJson(...).GetString(); -ReflectiveRapidJSON::JsonReflector::fromJson ("..."); +ReflectiveRapidJSON::JsonReflector::fromJson<ThridPartyStruct>("..."); -struct SomeStruct : public JsonSerializable{ +struct SomeStruct : public JsonSerializable<SomeStruct> { REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(SomeStruct); public: