1 #include "../json/reflector.h" 2 #include "../json/serializable.h" 4 #include <c++utilities/conversion/stringbuilder.h> 5 #include <c++utilities/conversion/stringconversion.h> 6 #include <c++utilities/io/misc.h> 7 #include <c++utilities/tests/testutils.h> 9 using TestUtilities::operator<<;
10 #include <cppunit/TestFixture.h> 11 #include <cppunit/extensions/HelperMacros.h> 13 #include <rapidjson/document.h> 14 #include <rapidjson/stringbuffer.h> 15 #include <rapidjson/writer.h> 21 #include <unordered_map> 50 map<string, int> someMap;
51 unordered_map<string, bool> someHash;
61 vector<TestObject> testObjects;
70 enum class SomeEnumClass {
78 namespace JsonReflector {
80 template <>
inline void push<TestObject>(
const TestObject &reflectable, Value::Object &value, Document::AllocatorType &allocator)
82 push(reflectable.number,
"number", value, allocator);
83 push(reflectable.number2,
"number2", value, allocator);
84 push(reflectable.numbers,
"numbers", value, allocator);
85 push(reflectable.text,
"text", value, allocator);
86 push(reflectable.boolean,
"boolean", value, allocator);
87 push(reflectable.someMap,
"someMap", value, allocator);
88 push(reflectable.someHash,
"someHash", value, allocator);
91 template <>
inline void push<NestingObject>(
const NestingObject &reflectable, Value::Object &value, Document::AllocatorType &allocator)
93 push(reflectable.name,
"name", value, allocator);
94 push(reflectable.testObj,
"testObj", value, allocator);
97 template <>
inline void push<NestingArray>(
const NestingArray &reflectable, Value::Object &value, Document::AllocatorType &allocator)
99 push(reflectable.name,
"name", value, allocator);
100 push(reflectable.testObjects,
"testObjects", value, allocator);
104 inline void pull<TestObject>(TestObject &reflectable,
const GenericValue<UTF8<char>>::ConstObject &value,
JsonDeserializationErrors *errors)
106 const char *previousRecord;
108 previousRecord = errors->currentRecord;
109 errors->currentRecord =
"TestObject";
111 pull(reflectable.number,
"number", value, errors);
112 pull(reflectable.number2,
"number2", value, errors);
113 pull(reflectable.numbers,
"numbers", value, errors);
114 pull(reflectable.text,
"text", value, errors);
115 pull(reflectable.boolean,
"boolean", value, errors);
116 pull(reflectable.someMap,
"someMap", value, errors);
117 pull(reflectable.someHash,
"someHash", value, errors);
119 errors->currentRecord = previousRecord;
124 inline void pull<NestingObject>(NestingObject &reflectable,
const GenericValue<UTF8<char>>::ConstObject &value,
JsonDeserializationErrors *errors)
126 const char *previousRecord;
128 previousRecord = errors->currentRecord;
129 errors->currentRecord =
"NestingObject";
131 pull(reflectable.name,
"name", value, errors);
132 pull(reflectable.testObj,
"testObj", value, errors);
134 errors->currentRecord = previousRecord;
139 inline void pull<NestingArray>(NestingArray &reflectable,
const GenericValue<UTF8<char>>::ConstObject &value,
JsonDeserializationErrors *errors)
141 const char *previousRecord;
143 previousRecord = errors->currentRecord;
144 errors->currentRecord =
"NestingArray";
146 pull(reflectable.name,
"name", value, errors);
147 pull(reflectable.testObjects,
"testObjects", value, errors);
149 errors->currentRecord = previousRecord;
166 CPPUNIT_TEST(testSerializePrimitives);
167 CPPUNIT_TEST(testSerializeSimpleObjects);
168 CPPUNIT_TEST(testSerializeNestedObjects);
169 CPPUNIT_TEST(testSerializeUniquePtr);
170 CPPUNIT_TEST(testSerializeSharedPtr);
171 CPPUNIT_TEST(testDeserializePrimitives);
172 CPPUNIT_TEST(testDeserializeSimpleObjects);
173 CPPUNIT_TEST(testDeserializeNestedObjects);
174 CPPUNIT_TEST(testDeserializeUniquePtr);
175 CPPUNIT_TEST(testDeserializeSharedPtr);
176 CPPUNIT_TEST(testHandlingParseError);
177 CPPUNIT_TEST(testHandlingTypeMismatch);
178 CPPUNIT_TEST_SUITE_END();
185 void testSerializePrimitives();
186 void testSerializeSimpleObjects();
187 void testSerializeNestedObjects();
188 void testSerializeUniquePtr();
189 void testSerializeSharedPtr();
190 void testDeserializePrimitives();
191 void testDeserializeSimpleObjects();
192 void testDeserializeNestedObjects();
193 void testDeserializeUniquePtr();
194 void testDeserializeSharedPtr();
195 void testHandlingParseError();
196 void testHandlingTypeMismatch();
216 Document doc(kArrayType);
217 Document::AllocatorType &alloc = doc.GetAllocator();
219 Document::Array array(doc.GetArray());
222 const string foo(
"foo");
223 JsonReflector::push<string>(foo, array, alloc);
224 JsonReflector::push<const char *>(
"bar", array, alloc);
226 JsonReflector::push<int>(25, array, alloc);
227 JsonReflector::push<double>(12.5, array, alloc);
229 JsonReflector::push<SomeEnum>(SomeEnumItem2, array, alloc);
230 JsonReflector::push<SomeEnumClass>(SomeEnumClass::Item2, array, alloc);
231 JsonReflector::push<SomeEnumClass>(SomeEnumClass::Item3, array, alloc);
233 JsonReflector::push<vector<const char *>>({
"foo1",
"bar1" }, array, alloc);
234 JsonReflector::push<list<const char *>>({
"foo2",
"bar2" }, array, alloc);
235 JsonReflector::push<initializer_list<const char *>>({
"foo3",
"bar3" }, array, alloc);
236 JsonReflector::push<tuple<int, double>>(make_tuple(2, 413.0), array, alloc);
238 JsonReflector::push<bool>(
true, array, alloc);
239 JsonReflector::push<bool>(
false, array, alloc);
242 Writer<StringBuffer> jsonWriter(strbuf);
243 doc.Accept(jsonWriter);
244 CPPUNIT_ASSERT_EQUAL(
"[\"foo\",\"bar\",25,12.5,1,1,2,[\"foo1\",\"bar1\"],[\"foo2\",\"bar2\"],[\"foo3\",\"bar3\"],[2,413.0],true,false]"s,
245 string(strbuf.GetString()));
255 testObj.number2 = 3.141592653589793;
256 testObj.numbers = { 1, 2, 3, 4 };
257 testObj.text =
"test";
258 testObj.boolean =
false;
259 testObj.someMap = { {
"a", 1 }, {
"b", 2 } };
260 testObj.someHash = { {
"c",
true }, {
"d",
false } };
261 CPPUNIT_ASSERT_EQUAL(
262 "{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false,\"someMap\":{\"a\":1,\"b\":2},\"someHash\":{\"d\":false,\"c\":true}}"s,
263 string(testObj.toJson().GetString()));
271 NestingObject nestingObj;
272 nestingObj.name =
"nesting";
273 TestObject &testObj = nestingObj.testObj;
275 testObj.number2 = 3.141592653589793;
276 testObj.numbers = { 1, 2, 3, 4 };
277 testObj.text =
"test";
278 testObj.boolean =
false;
279 CPPUNIT_ASSERT_EQUAL(
280 "{\"name\":\"nesting\",\"testObj\":{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false,\"someMap\":{},\"someHash\":{}}}"s,
281 string(nestingObj.toJson().GetString()));
283 NestingArray nestingArray;
284 nestingArray.name =
"nesting2";
285 nestingArray.testObjects.emplace_back(testObj);
286 nestingArray.testObjects.emplace_back(testObj);
287 nestingArray.testObjects.back().number = 43;
288 CPPUNIT_ASSERT_EQUAL(
289 "{\"name\":\"nesting2\",\"testObjects\":[{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false,\"someMap\":{},\"someHash\":{}},{\"number\":43,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false,\"someMap\":{},\"someHash\":{}}]}"s,
290 string(nestingArray.toJson().GetString()));
292 vector<TestObject> nestedInVector;
293 nestedInVector.emplace_back(testObj);
294 CPPUNIT_ASSERT_EQUAL(
295 "[{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false,\"someMap\":{},\"someHash\":{}}]"s,
301 Document doc(kArrayType);
302 Document::AllocatorType &alloc = doc.GetAllocator();
304 Document::Array array(doc.GetArray());
306 const auto str = make_unique<string>(
"foo");
307 std::unique_ptr<string> nullStr;
308 const auto obj = make_unique<TestObject>();
310 obj->number2 = 3.141592653589793;
311 obj->numbers = { 1, 2, 3, 4 };
313 obj->boolean =
false;
320 Writer<StringBuffer> jsonWriter(strbuf);
321 doc.Accept(jsonWriter);
322 CPPUNIT_ASSERT_EQUAL(
323 "[\"foo\",null,{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"bar\",\"boolean\":false,\"someMap\":{},\"someHash\":{}}]"s,
324 string(strbuf.GetString()));
329 Document doc(kArrayType);
330 Document::AllocatorType &alloc = doc.GetAllocator();
332 Document::Array array(doc.GetArray());
334 const auto str = make_shared<string>(
"foo");
335 std::unique_ptr<string> nullStr;
336 const auto obj = make_shared<TestObject>();
338 obj->number2 = 3.141592653589793;
339 obj->numbers = { 1, 2, 3, 4 };
341 obj->boolean =
false;
348 Writer<StringBuffer> jsonWriter(strbuf);
349 doc.Accept(jsonWriter);
350 CPPUNIT_ASSERT_EQUAL(
351 "[\"foo\",null,{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"bar\",\"boolean\":false,\"someMap\":{},\"someHash\":{}}]"s,
352 string(strbuf.GetString()));
360 Document doc(kArrayType);
362 doc.Parse(
"[\"a\", 5, 5.0, 5e6, 4, \"test\", true, 4.125, false]");
363 auto array = doc.GetArray().begin();
366 int int1 = 0, int2 = 0;
367 bool bool1 =
false, bool2 =
true;
368 float float1 = 0.0f, float2 = 0.0f;
369 double double1 = 0.0;
381 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
382 CPPUNIT_ASSERT_EQUAL(
"a"s, str1);
383 CPPUNIT_ASSERT_EQUAL(5, int1);
384 CPPUNIT_ASSERT_EQUAL(5, int2);
385 CPPUNIT_ASSERT_EQUAL(5e6f, float1);
386 CPPUNIT_ASSERT_EQUAL(4.f, float2);
387 CPPUNIT_ASSERT_EQUAL(
"test"s, str2);
388 CPPUNIT_ASSERT_EQUAL(
true, bool1);
389 CPPUNIT_ASSERT_EQUAL(4.125, double1);
390 CPPUNIT_ASSERT_EQUAL(
false, bool2);
393 tuple<string, int, int, float, float, string, bool, double, bool> arrayAsTuple;
395 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
396 CPPUNIT_ASSERT_EQUAL(
"a"s, get<0>(arrayAsTuple));
397 CPPUNIT_ASSERT_EQUAL(5, get<1>(arrayAsTuple));
398 CPPUNIT_ASSERT_EQUAL(5, get<2>(arrayAsTuple));
399 CPPUNIT_ASSERT_EQUAL(5e6f, get<3>(arrayAsTuple));
400 CPPUNIT_ASSERT_EQUAL(4.f, get<4>(arrayAsTuple));
401 CPPUNIT_ASSERT_EQUAL(
"test"s, get<5>(arrayAsTuple));
402 CPPUNIT_ASSERT_EQUAL(
true, get<6>(arrayAsTuple));
403 CPPUNIT_ASSERT_EQUAL(4.125, get<7>(arrayAsTuple));
404 CPPUNIT_ASSERT_EQUAL(
false, get<8>(arrayAsTuple));
405 tuple<string, int> anotherTuple;
407 CPPUNIT_ASSERT_EQUAL(1_st, errors.size());
408 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::ArraySizeMismatch, errors.front().kind);
416 const TestObject testObj(
TestObject::fromJson(
"{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":" 417 "false,\"someMap\":{\"a\":1,\"b\":2},\"someHash\":{\"c\":true,\"d\":false}}"));
419 CPPUNIT_ASSERT_EQUAL(42, testObj.number);
420 CPPUNIT_ASSERT_EQUAL(3.141592653589793, testObj.number2);
421 CPPUNIT_ASSERT_EQUAL(vector<int>({ 1, 2, 3, 4 }), testObj.numbers);
422 CPPUNIT_ASSERT_EQUAL(
"test"s, testObj.text);
423 CPPUNIT_ASSERT_EQUAL(
false, testObj.boolean);
424 const map<string, int> expectedMap{ {
"a", 1 }, {
"b", 2 } };
425 CPPUNIT_ASSERT_EQUAL(expectedMap, testObj.someMap);
426 const unordered_map<string, bool> expectedHash{ {
"c",
true }, {
"d",
false } };
427 CPPUNIT_ASSERT_EQUAL(expectedHash, testObj.someHash);
436 const NestingObject nestingObj(
NestingObject::fromJson(
"{\"name\":\"nesting\",\"testObj\":{\"number\":42,\"number2\":3.141592653589793," 437 "\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false}}",
439 const TestObject &testObj = nestingObj.testObj;
440 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
441 CPPUNIT_ASSERT_EQUAL(
"nesting"s, nestingObj.name);
442 CPPUNIT_ASSERT_EQUAL(42, testObj.number);
443 CPPUNIT_ASSERT_EQUAL(3.141592653589793, testObj.number2);
444 CPPUNIT_ASSERT_EQUAL(vector<int>({ 1, 2, 3, 4 }), testObj.numbers);
445 CPPUNIT_ASSERT_EQUAL(
"test"s, testObj.text);
446 CPPUNIT_ASSERT_EQUAL(
false, testObj.boolean);
448 const NestingArray nestingArray(
NestingArray::fromJson(
"{\"name\":\"nesting2\",\"testObjects\":[{\"number\":42,\"number2\":3.141592653589793," 449 "\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false},{\"number\":43,\"number2\":3." 450 "141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false}]}",
452 const vector<TestObject> &testObjects = nestingArray.testObjects;
453 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
454 CPPUNIT_ASSERT_EQUAL(
"nesting2"s, nestingArray.name);
455 CPPUNIT_ASSERT_EQUAL(2_st, testObjects.size());
456 CPPUNIT_ASSERT_EQUAL(42, testObjects[0].number);
457 CPPUNIT_ASSERT_EQUAL(43, testObjects[1].number);
458 for (
const TestObject &testObj : testObjects) {
459 CPPUNIT_ASSERT_EQUAL(3.141592653589793, testObj.number2);
460 CPPUNIT_ASSERT_EQUAL(vector<int>({ 1, 2, 3, 4 }), testObj.numbers);
461 CPPUNIT_ASSERT_EQUAL(
"test"s, testObj.text);
462 CPPUNIT_ASSERT_EQUAL(
false, testObj.boolean);
466 "[{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false,\"someMap\":{},\"someHash\":{}}]",
468 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
469 CPPUNIT_ASSERT_EQUAL(1_st, nestedInVector.size());
470 CPPUNIT_ASSERT_EQUAL(42, nestedInVector[0].number);
471 CPPUNIT_ASSERT_EQUAL(4_st, nestedInVector[0].numbers.size());
472 CPPUNIT_ASSERT_EQUAL(
"test"s, nestedInVector[0].text);
477 Document doc(kArrayType);
478 doc.Parse(
"[\"foo\",null,{\"text\":\"bar\"}]");
479 auto array = doc.GetArray().begin();
481 unique_ptr<string> str;
482 unique_ptr<string> nullStr;
483 unique_ptr<TestObject> obj;
489 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
491 CPPUNIT_ASSERT_EQUAL(
"foo"s, *str);
492 CPPUNIT_ASSERT(!nullStr);
494 CPPUNIT_ASSERT_EQUAL(
"bar"s, obj->text);
499 Document doc(kArrayType);
500 doc.Parse(
"[\"foo\",null,{\"text\":\"bar\"}]");
501 auto array = doc.GetArray().begin();
503 shared_ptr<string> str;
504 shared_ptr<string> nullStr;
505 shared_ptr<TestObject> obj;
511 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
513 CPPUNIT_ASSERT_EQUAL(
"foo"s, *str);
514 CPPUNIT_ASSERT(!nullStr);
516 CPPUNIT_ASSERT_EQUAL(
"bar"s, obj->text);
525 NestingObject::fromJson(
"{\"name\":nesting\",\"testObj\":{\"number\":42,\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":" 526 "\"test\",\"boolean\":false}}");
527 CPPUNIT_FAIL(
"expected ParseResult thrown");
528 }
catch (
const RAPIDJSON_NAMESPACE::ParseResult &res) {
529 CPPUNIT_ASSERT_EQUAL(RAPIDJSON_NAMESPACE::kParseErrorValueInvalid, res.Code());
530 CPPUNIT_ASSERT_EQUAL(9_st, res.Offset());
540 NestingArray::fromJson(
"{\"name\":\"nesting2\",\"testObjects\":[{\"number\":42,\"number2\":3.141592653589793," 541 "\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false},{\"number\":43,\"number2\":3." 542 "141592653589793,\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false}]}",
544 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
546 NestingObject::fromJson(
"{\"name\":\"nesting\",\"testObj\":{\"number\":\"42\",\"number2\":3.141592653589793,\"numbers\":[1,2,3,4],\"text\":" 547 "\"test\",\"boolean\":false}}",
549 CPPUNIT_ASSERT_EQUAL(1_st, errors.size());
550 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors.front().kind);
551 CPPUNIT_ASSERT_EQUAL(JsonType::Number, errors.front().expectedType);
552 CPPUNIT_ASSERT_EQUAL(JsonType::String, errors.front().actualType);
553 CPPUNIT_ASSERT_EQUAL(
"number"s,
string(errors.front().member));
554 CPPUNIT_ASSERT_EQUAL(
"TestObject"s,
string(errors.front().record));
557 NestingObject::fromJson(
"{\"name\":\"nesting\",\"testObj\":{\"number\":42,\"number2\":3.141592653589793,\"numbers\":1,\"text\":" 558 "\"test\",\"boolean\":false}}",
560 CPPUNIT_ASSERT_EQUAL(1_st, errors.size());
561 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors.front().kind);
562 CPPUNIT_ASSERT_EQUAL(JsonType::Array, errors.front().expectedType);
563 CPPUNIT_ASSERT_EQUAL(JsonType::Number, errors.front().actualType);
564 CPPUNIT_ASSERT_EQUAL(
"numbers"s,
string(errors.front().member));
565 CPPUNIT_ASSERT_EQUAL(
"TestObject"s,
string(errors.front().record));
569 CPPUNIT_ASSERT_EQUAL(2_st, errors.size());
570 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors.front().kind);
571 CPPUNIT_ASSERT_EQUAL(JsonType::String, errors.front().expectedType);
572 CPPUNIT_ASSERT_EQUAL(JsonType::Array, errors.front().actualType);
573 CPPUNIT_ASSERT_EQUAL(
"name"s,
string(errors.front().member));
574 CPPUNIT_ASSERT_EQUAL(
"NestingObject"s,
string(errors.front().record));
575 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors.back().kind);
576 CPPUNIT_ASSERT_EQUAL(JsonType::Object, errors.back().expectedType);
577 CPPUNIT_ASSERT_EQUAL(JsonType::String, errors.back().actualType);
578 CPPUNIT_ASSERT_EQUAL(
"testObj"s,
string(errors.back().member));
579 CPPUNIT_ASSERT_EQUAL(
"NestingObject"s,
string(errors.back().record));
582 const NestingArray nestingArray(
583 NestingArray::fromJson(
"{\"name\":\"nesting2\",\"testObjects\":[25,{\"number\":42,\"number2\":3.141592653589793," 584 "\"numbers\":[1,2,3,4],\"text\":\"test\",\"boolean\":false},\"foo\",{\"number\":43,\"number2\":3." 585 "141592653589793,\"numbers\":[1,2,3,4,\"bar\"],\"text\":\"test\",\"boolean\":false}]}",
587 CPPUNIT_ASSERT_EQUAL(3_st, errors.size());
588 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors[0].kind);
589 CPPUNIT_ASSERT_EQUAL(JsonType::Object, errors[0].expectedType);
590 CPPUNIT_ASSERT_EQUAL(JsonType::Number, errors[0].actualType);
591 CPPUNIT_ASSERT_EQUAL(
"testObjects"s,
string(errors[0].member));
592 CPPUNIT_ASSERT_EQUAL(
"NestingArray"s,
string(errors[0].record));
593 CPPUNIT_ASSERT_EQUAL(0_st, errors[0].index);
594 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors[1].kind);
595 CPPUNIT_ASSERT_EQUAL(JsonType::Object, errors[1].expectedType);
596 CPPUNIT_ASSERT_EQUAL(JsonType::String, errors[1].actualType);
597 CPPUNIT_ASSERT_EQUAL(2_st, errors[1].index);
598 CPPUNIT_ASSERT_EQUAL(
"testObjects"s,
string(errors[1].member));
599 CPPUNIT_ASSERT_EQUAL(
"NestingArray"s,
string(errors[1].record));
600 CPPUNIT_ASSERT_EQUAL(JsonDeserializationErrorKind::TypeMismatch, errors[2].kind);
601 CPPUNIT_ASSERT_EQUAL(JsonType::Number, errors[2].expectedType);
602 CPPUNIT_ASSERT_EQUAL(JsonType::String, errors[2].actualType);
603 CPPUNIT_ASSERT_EQUAL(
"numbers"s,
string(errors[2].member));
604 CPPUNIT_ASSERT_EQUAL(
"TestObject"s,
string(errors[2].record));
605 CPPUNIT_ASSERT_EQUAL(4_st, errors[2].index);
608 errors.
throwOn = JsonDeserializationErrors::ThrowOn::TypeMismatch;
Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< IsMapOrHash< Type > >> IsArray
void testSerializeUniquePtr()
The JsonReflectorTests class tests RapidJSON wrapper which is used to ease code generation.
void testDeserializePrimitives()
Tests deserializing strings, numbers (int, float, double) and boolean.
void testDeserializeNestedObjects()
Tests deserializing nested objects and arrays.
void testDeserializeSimpleObjects()
Tests deserializing simple objects.
Traits::Any< Traits::IsSpecializationOf< Type, std::map >, Traits::IsSpecializationOf< Type, std::unordered_map > > IsMapOrHash
RAPIDJSON_NAMESPACE::StringBuffer toJson(const Type &reflectable)
Serializes the specified reflectable which has a custom type or can be mapped to and object...
void testSerializeNestedObjects()
Tests serializing nested object and arrays.
void testSerializeSharedPtr()
enum ReflectiveRapidJSON::JsonDeserializationErrors::ThrowOn throwOn
void testDeserializeSharedPtr()
void testSerializeSimpleObjects()
Tests serializing objects.
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
Type fromJson(const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors=nullptr)
Deserializes the specified JSON to.
void pull(Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstObject &value, JsonDeserializationErrors *errors)
Pulls the reflectable which has a custom type from the specified object.
CPPUNIT_TEST_SUITE_REGISTRATION(JsonReflectorTests)
The JsonDeserializationError struct describes any errors of fromJson() except such caused by invalid ...
void testHandlingTypeMismatch()
Tests whether JsonDeserializationError is thrown on type mismatch.
void testHandlingParseError()
Tests whether RAPIDJSON_NAMESPACE::ParseResult is thrown correctly when passing invalid JSON to fromJ...
void testSerializePrimitives()
Tests serializing strings, numbers, arrays and boolean.
void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Pushes the specified reflectable to the specified value.
The JsonSerializable class provides the CRTP-base for (de)serializable objects.
void testDeserializeUniquePtr()