Escape angle brackets in README
This commit is contained in:
parent
25e7891573
commit
7fcbead8e3
36
README.md
36
README.md
|
@ -79,28 +79,28 @@ The following table shows the mapping of supported C++ types to supported JSON t
|
||||||
## Usage
|
## Usage
|
||||||
This example shows how the library can be used to make a `struct` serializable:
|
This example shows how the library can be used to make a `struct` serializable:
|
||||||
<pre>
|
<pre>
|
||||||
#include <reflective_rapidjson/json/serializable.h>
|
#include <reflective_rapidjson/json/serializable.h>
|
||||||
|
|
||||||
// define structures, eg.
|
// define structures, eg.
|
||||||
struct TestObject : public ReflectiveRapidJSON::JsonSerializable<TestObject> {
|
struct TestObject : public ReflectiveRapidJSON::JsonSerializable<TestObject> {
|
||||||
int number;
|
int number;
|
||||||
double number2;
|
double number2;
|
||||||
vector<int> numbers;
|
vector<int> numbers;
|
||||||
string text;
|
string text;
|
||||||
bool boolean;
|
bool boolean;
|
||||||
};
|
};
|
||||||
struct NestingObject : public ReflectiveRapidJSON::JsonSerializable<NestingObject> {
|
struct NestingObject : public ReflectiveRapidJSON::JsonSerializable<NestingObject> {
|
||||||
string name;
|
string name;
|
||||||
TestObject testObj;
|
TestObject testObj;
|
||||||
};
|
};
|
||||||
struct NestingArray : public ReflectiveRapidJSON::JsonSerializable<NestingArray> {
|
struct NestingArray : public ReflectiveRapidJSON::JsonSerializable<NestingArray> {
|
||||||
string name;
|
string name;
|
||||||
vector<TestObject> testObjects;
|
vector<TestObject> testObjects;
|
||||||
};
|
};
|
||||||
|
|
||||||
// serialize to JSON
|
// serialize to JSON
|
||||||
NestingArray obj{ ... };
|
NestingArray obj{ ... };
|
||||||
cout << "JSON: " << obj.toJson().GetString();
|
cout << "JSON: " << obj.toJson().GetString();
|
||||||
|
|
||||||
// deserialize from JSON
|
// deserialize from JSON
|
||||||
const auto obj = NestingArray::fromJson(...);
|
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):
|
It works very similar to the example above. Just use the `BinarySerializable` class instead (or in addition):
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
#include <reflective_rapidjson/binary/serializable.h>
|
#include <reflective_rapidjson/binary/serializable.h>
|
||||||
struct TestObject : public ReflectiveRapidJSON::BinarySerializable<TestObject>
|
struct TestObject : public ReflectiveRapidJSON::BinarySerializable<TestObject>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
#### Invoking code generator with CMake macro
|
#### 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.
|
The same example as above. However, this time Boost.Hana is used - so it doesn't require invoking the generator.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
#include "<reflective_rapidjson/json/serializable-boosthana.h>
|
#include "<reflective_rapidjson/json/serializable-boosthana.h>
|
||||||
|
|
||||||
// define structures using BOOST_HANA_DEFINE_STRUCT, eg.
|
// define structures using BOOST_HANA_DEFINE_STRUCT, eg.
|
||||||
struct TestObject : public JsonSerializable<TestObject> {
|
struct TestObject : public JsonSerializable<TestObject> {
|
||||||
BOOST_HANA_DEFINE_STRUCT(TestObject,
|
BOOST_HANA_DEFINE_STRUCT(TestObject,
|
||||||
(int, number),
|
(int, number),
|
||||||
(double, number2),
|
(double, number2),
|
||||||
(vector<int>, numbers),
|
(vector<int>, numbers),
|
||||||
(string, text),
|
(string, text),
|
||||||
(bool, boolean)
|
(bool, boolean)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
struct NestingObject : public JsonSerializable<NestingObject> {
|
struct NestingObject : public JsonSerializable<NestingObject> {
|
||||||
BOOST_HANA_DEFINE_STRUCT(NestingObject,
|
BOOST_HANA_DEFINE_STRUCT(NestingObject,
|
||||||
(string, name),
|
(string, name),
|
||||||
(TestObject, testObj)
|
(TestObject, testObj)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
struct NestingArray : public JsonSerializable<NestingArray> {
|
struct NestingArray : public JsonSerializable<NestingArray> {
|
||||||
BOOST_HANA_DEFINE_STRUCT(NestingArray,
|
BOOST_HANA_DEFINE_STRUCT(NestingArray,
|
||||||
(string, name),
|
(string, name),
|
||||||
(vector<TestObject>, testObjects)
|
(vector<TestObject>, testObjects)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// serialize to JSON
|
// serialize to JSON
|
||||||
NestingArray obj{ ... };
|
NestingArray obj{ ... };
|
||||||
cout << "JSON: " << obj.toJson().GetString();
|
cout << "JSON: " << obj.toJson().GetString();
|
||||||
|
|
||||||
// deserialize from JSON
|
// deserialize from JSON
|
||||||
const auto obj = NestingArray::fromJson(...);
|
const auto obj = NestingArray::fromJson(...);
|
||||||
|
@ -266,7 +266,7 @@ REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(ThridPartyStruct)
|
||||||
|
|
||||||
// (de)serialization
|
// (de)serialization
|
||||||
ReflectiveRapidJSON::JsonReflector::toJson(...).GetString();
|
ReflectiveRapidJSON::JsonReflector::toJson(...).GetString();
|
||||||
ReflectiveRapidJSON::JsonReflector::fromJson<ThridPartyStruct>("...");
|
ReflectiveRapidJSON::JsonReflector::fromJson<ThridPartyStruct>("...");
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
The code generator will emit the code in the same way as if `JsonSerializable` was
|
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:
|
To make things easier, there's a macro provided:
|
||||||
<pre>
|
<pre>
|
||||||
struct SomeStruct : public JsonSerializable<SomeStruct> {
|
struct SomeStruct : public JsonSerializable<SomeStruct> {
|
||||||
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(SomeStruct);
|
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(SomeStruct);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue