1 #ifndef REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H
2 #define REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H
10 #include "../traits.h"
12 #include <rapidjson/document.h>
13 #include <rapidjson/rapidjson.h>
14 #include <rapidjson/stringbuffer.h>
15 #include <rapidjson/writer.h>
32 static constexpr
const char *
name =
"AdaptedJsonSerializable";
33 static constexpr
const char *
qualifiedName =
"ReflectiveRapidJSON::AdaptedJsonSerializable";
39 namespace JsonReflector {
46 return size > std::numeric_limits<RAPIDJSON_NAMESPACE::SizeType>::max() ? std::numeric_limits<RAPIDJSON_NAMESPACE::SizeType>::max()
47 : static_cast<RAPIDJSON_NAMESPACE::SizeType>(size);
55 RAPIDJSON_NAMESPACE::StringBuffer buffer;
56 RAPIDJSON_NAMESPACE::Writer<RAPIDJSON_NAMESPACE::StringBuffer> writer(buffer);
57 document.Accept(writer);
66 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kObjectType);
67 const RAPIDJSON_NAMESPACE::ParseResult parseRes = document.Parse(json, jsonSize);
68 if (parseRes.IsError()) {
75 template <
typename Type>
76 using IsBuiltInType = Traits::Any<std::is_integral<Type>, std::is_floating_point<Type>, std::is_pointer<Type>, std::is_enum<Type>,
77 Traits::IsSpecializationOf<Type, std::tuple>, Traits::IsIteratable<Type>, Traits::IsSpecializationOf<Type, std::unique_ptr>,
78 Traits::IsSpecializationOf<Type, std::shared_ptr>, Traits::IsSpecializationOf<Type, std::weak_ptr>>;
79 template <
typename Type>
using IsCustomType = Traits::Not<IsBuiltInType<Type>>;
83 template <
typename Type>
92 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> * =
nullptr>
93 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
98 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>> * =
nullptr>
99 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
104 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>> * =
nullptr>
105 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
110 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>> * =
nullptr>
112 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
117 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>> * =
nullptr>
119 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
125 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> * =
nullptr>
126 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
131 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
132 inline void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
135 RAPIDJSON_NAMESPACE::Value::Object obj(value.GetObject());
136 push(reflectable, obj, allocator);
142 template <
typename Type, Traits::EnableIfAny<std::is_
integral<Type>, std::is_
floating_po
int<Type>> * =
nullptr>
143 inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
145 value.Set(reflectable, allocator);
151 template <
typename Type, Traits::EnableIfAny<std::is_enum<Type>> * =
nullptr>
152 inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
154 value.Set(
static_cast<Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type
>, std::uint64_t, std::int64_t>>(reflectable),
161 template <
typename Type, Traits::EnableIf<std::is_same<Type, const
char *>> * =
nullptr>
162 inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
164 value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), allocator);
170 template <
typename Type, Traits::EnableIf<std::is_same<Type, const
char *const &>> * =
nullptr>
171 inline void push(
const char *
const &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
173 value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), allocator);
179 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>> * =
nullptr>
180 inline void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
182 value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), allocator);
188 template <
typename Type, Traits::EnableIf<IsArrayOrSet<Type>, Traits::HasSize<Type>> * =
nullptr>
189 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
192 RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray());
193 array.Reserve(reflectable.size(), allocator);
194 for (
const auto &item : reflectable) {
195 push(item, array, allocator);
202 template <
typename Type, Traits::EnableIf<IsArrayOrSet<Type>, Traits::Not<Traits::HasSize<Type>>> * =
nullptr>
203 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
206 RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray());
207 for (
const auto &item : reflectable) {
208 push(item, array, allocator);
216 template <
typename Type, Traits::EnableIfAny<IsMapOrHash<Type>, IsMultiMapOrHash<Type>> * =
nullptr>
217 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
220 RAPIDJSON_NAMESPACE::Value::Object object(value.GetObject());
221 for (
const auto &item : reflectable) {
222 push(item.second, item.first.data(), object, allocator);
232 static void push(
const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
240 static void push(
const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
250 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::tuple>> * =
nullptr>
251 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
254 RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray());
255 array.Reserve(std::tuple_size<Type>::value, allocator);
256 Detail::TuplePushHelper<Type, std::tuple_size<Type>::value>
::push(reflectable, array, allocator);
262 template <
typename Type,
263 Traits::EnableIfAny<Traits::IsSpecializationOf<Type, std::unique_ptr>, Traits::IsSpecializationOf<Type, std::shared_ptr>,
264 Traits::IsSpecializationOf<Type, std::weak_ptr>> * =
nullptr>
265 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
271 push(*reflectable, value, allocator);
277 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>> *>
278 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
280 RAPIDJSON_NAMESPACE::Value objectValue(RAPIDJSON_NAMESPACE::kObjectType);
281 RAPIDJSON_NAMESPACE::Value::Object object(objectValue.GetObject());
282 push(reflectable,
object, allocator);
283 value.PushBack(objectValue, allocator);
289 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>> *>
290 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
292 RAPIDJSON_NAMESPACE::Value genericValue;
293 push(reflectable, genericValue, allocator);
294 value.PushBack(genericValue, allocator);
300 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>> *>
302 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
304 RAPIDJSON_NAMESPACE::Value objectValue(RAPIDJSON_NAMESPACE::kObjectType);
305 RAPIDJSON_NAMESPACE::Value::Object object(objectValue.GetObject());
306 push(reflectable,
object, allocator);
307 value.AddMember(RAPIDJSON_NAMESPACE::StringRef(name), objectValue, allocator);
313 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>> *>
315 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
317 RAPIDJSON_NAMESPACE::Value genericValue;
318 push(reflectable, genericValue, allocator);
319 value.AddMember(RAPIDJSON_NAMESPACE::StringRef(name), genericValue, allocator);
328 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> * =
nullptr>
329 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
330 JsonDeserializationErrors *errors);
335 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> * =
nullptr>
336 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
341 template <
typename Type, Traits::EnableIf<IsArrayOrSet<Type>, Traits::Not<Traits::IsReservable<Type>>> * =
nullptr>
342 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
347 template <
typename Type, Traits::EnableIf<IsArrayOrSet<Type>, Traits::IsReservable<Type>> * =
nullptr>
348 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
353 template <
typename Type, Traits::EnableIf<IsArray<Type>> * =
nullptr>
354 void pull(Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstArray array, JsonDeserializationErrors *errors);
359 template <
typename Type, Traits::EnableIf<IsSet<Type>> * =
nullptr>
360 void pull(Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstArray array, JsonDeserializationErrors *errors);
365 template <
typename Type, Traits::EnableIf<IsMultiSet<Type>> * =
nullptr>
366 void pull(Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstArray array, JsonDeserializationErrors *errors);
371 template <
typename Type, Traits::EnableIf<IsMapOrHash<Type>> * =
nullptr>
372 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
377 template <
typename Type, Traits::EnableIf<IsMultiMapOrHash<Type>> * =
nullptr>
378 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
383 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::tuple>> * =
nullptr>
384 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
389 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::unique_ptr>> * =
nullptr>
390 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
395 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::shared_ptr>> * =
nullptr>
396 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
401 template <
typename Type>
403 Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ValueIterator &value, JsonDeserializationErrors *errors);
410 template <
typename Type>
411 inline void pull(Type &reflectable,
const char *name,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
412 JsonDeserializationErrors *errors);
417 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
418 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
423 template <
typename Type,
424 Traits::EnableIf<Traits::Not<std::is_same<Type, bool>>, Traits::Any<std::is_integral<Type>, std::is_floating_point<Type>>> * =
nullptr>
426 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors *errors)
428 if (!value.IsNumber()) {
434 reflectable = value.Is<Type>() ? value.Get<Type>() : static_cast<Type>(value.GetDouble());
440 template <
typename Type, Traits::EnableIf<std::is_same<Type,
bool>> * =
nullptr>
442 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors *errors)
444 if (!value.IsBool()) {
450 reflectable = value.GetBool();
457 template <
typename Type, Traits::EnableIfAny<std::is_enum<Type>> * =
nullptr>
459 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
461 using ExpectedType = Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, std::uint64_t, std::int64_t>;
462 if (!value.Is<ExpectedType>()) {
464 errors->reportTypeMismatch<ExpectedType>(value.GetType());
468 reflectable = static_cast<Type>(value.Get<ExpectedType>());
474 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>> * =
nullptr>
476 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
478 if (!value.IsString()) {
480 errors->reportTypeMismatch<std::string>(value.GetType());
484 reflectable = value.GetString();
491 template <
typename Type, Traits::EnableIfAny<std::is_same<Type, const
char *>, std::is_same<Type, const
char *const &>> * =
nullptr>
492 inline void pull(Type &,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
494 if (!value.IsString()) {
496 errors->reportTypeMismatch<std::string>(value.GetType());
505 template <
typename Type, Traits::EnableIf<IsArrayOrSet<Type>, Traits::Not<Traits::IsReservable<Type>>> *>
508 if (!value.IsArray()) {
514 pull(reflectable, value.GetArray(), errors);
520 template <
typename Type, Traits::EnableIf<IsArrayOrSet<Type>, Traits::IsReservable<Type>> *>
523 if (!value.IsArray()) {
529 auto array = value.GetArray();
530 reflectable.reserve(array.Size());
531 pull(reflectable, array, errors);
537 template <
typename Type, Traits::EnableIf<IsArray<Type>> *>
544 std::size_t index = 0;
545 for (
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &item : array) {
551 reflectable.emplace_back();
552 pull(reflectable.back(), item, errors);
564 template <
typename Type, Traits::EnableIf<IsMultiSet<Type>> *>
571 std::size_t index = 0;
572 for (
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &item : array) {
578 typename Type::value_type itemObj;
579 pull(itemObj, item, errors);
580 reflectable.emplace(move(itemObj));
592 template <
typename Type, Traits::EnableIf<IsSet<Type>> *>
593 void pull(Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstArray array, JsonDeserializationErrors *errors)
599 std::size_t index = 0;
600 for (
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &item : array) {
603 errors->currentIndex = index;
606 typename Type::value_type itemObj;
607 pull(itemObj, item, errors);
608 if (!reflectable.emplace(move(itemObj)).second) {
622 template <
typename Type, Traits::EnableIf<IsMapOrHash<Type>> *>
623 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
625 if (!value.IsObject()) {
627 errors->reportTypeMismatch<Type>(value.GetType());
631 auto obj = value.GetObject();
632 for (
auto i = obj.MemberBegin(), end = obj.MemberEnd(); i != end; ++i) {
633 pull(reflectable[i->name.GetString()], i->value, errors);
640 template <
typename Type, Traits::EnableIf<IsMultiMapOrHash<Type>> *>
641 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
643 if (!value.IsObject()) {
645 errors->reportTypeMismatch<Type>(value.GetType());
649 auto obj = value.GetObject();
650 for (
auto i = obj.MemberBegin(), end = obj.MemberEnd(); i != end; ++i) {
651 auto insertedIterator = reflectable.insert(
typename Type::value_type(i->name.GetString(),
typename Type::mapped_type()));
652 pull(insertedIterator->second, i->value, errors);
666 JsonReflector::pull<
typename std::tuple_element<N - 1, Tuple>::type>(std::get<N - 1>(tuple), value[N - 1], errors);
673 JsonReflector::pull<typename std::tuple_element<0, Tuple>::type>(std::get<0>(tuple), value[0], errors);
681 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::tuple>> *>
684 if (!value.IsArray()) {
690 auto array = value.GetArray();
691 if (array.Size() != std::tuple_size<Type>::value) {
698 Detail::TuplePullHelper<Type, std::tuple_size<Type>::value>
::pull(reflectable, array, errors);
704 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::unique_ptr>> *>
705 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
707 if (value.IsNull()) {
711 reflectable = std::make_unique<typename Type::element_type>();
712 pull(*reflectable, value, errors);
718 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::shared_ptr>> *>
719 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
721 if (value.IsNull()) {
725 reflectable = std::make_shared<typename Type::element_type>();
726 pull(*reflectable, value, errors);
732 template <
typename Type>
735 pull<Type>(reflectable, *value, errors);
744 template <
typename Type>
745 inline void pull(Type &reflectable,
const char *name,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
749 const auto member = value.FindMember(name);
750 if (member == value.MemberEnd()) {
755 const char *previousMember;
762 pull<Type>(reflectable, member->value, errors);
773 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
774 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors *errors)
776 if (!value.IsObject()) {
782 pull(reflectable, value.GetObject(), errors);
790 template <
typename Type, Traits::EnableIfAny<IsJsonSerializable<Type>, IsMapOrHash<Type>, IsMultiMapOrHash<Type>> * =
nullptr>
793 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kObjectType);
794 RAPIDJSON_NAMESPACE::Document::Object object(document.GetObject());
795 push(reflectable,
object, document.GetAllocator());
802 template <
typename Type, Traits::EnableIfAny<std::is_
integral<Type>, std::is_
floating_po
int<Type>> * =
nullptr>
805 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kNumberType);
806 document.Set(reflectable, document.GetAllocator());
813 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>> * =
nullptr>
816 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kStringType);
817 document.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), document.GetAllocator());
824 template <
typename Type, Traits::EnableIf<std::is_same<Type, const
char *>> * =
nullptr>
827 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kStringType);
828 document.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), document.GetAllocator());
835 template <
typename Type, Traits::EnableIf<IsArray<Type>> * =
nullptr> RAPIDJSON_NAMESPACE::Document
toJsonDocument(
const Type &reflectable)
837 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kArrayType);
838 push(reflectable, document, document.GetAllocator());
845 template <
typename Type,
846 Traits::EnableIfAny<IsJsonSerializable<Type>, IsMapOrHash<Type>, IsMultiMapOrHash<Type>, std::is_integral<Type>, std::is_floating_point<Type>,
847 Traits::IsString<Type>, IsArray<Type>> * =
nullptr>
848 RAPIDJSON_NAMESPACE::StringBuffer
toJson(
const Type &reflectable)
859 template <
typename Type, Traits::EnableIfAny<IsJsonSerializable<Type>, IsMapOrHash<Type>, IsMultiMapOrHash<Type>> * =
nullptr>
863 if (!doc.IsObject()) {
871 pull<Type>(res, doc.GetObject(), errors);
878 template <
typename Type, Traits::EnableIfAny<std::is_
integral<Type>, std::is_
floating_po
int<Type>> * =
nullptr>
882 if (!doc.Is<Type>()) {
889 return doc.Get<Type>();
895 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>> * =
nullptr>
896 Type
fromJson(
const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors =
nullptr)
899 if (!doc.IsString()) {
906 return doc.GetString();
912 template <
typename Type, Traits::EnableIf<IsArray<Type>> * =
nullptr>
913 Type
fromJson(
const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors =
nullptr)
916 if (!doc.IsArray()) {
924 pull<Type>(res, doc.GetArray(), errors);
933 return fromJson<Type>(json, std::strlen(json), errors);
941 return fromJson<Type>(json.data(), json.size(), errors);
947 #endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H