1 #ifndef REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H 2 #define REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H 10 #include <c++utilities/conversion/types.h> 11 #include <c++utilities/misc/traits.h> 13 #include <rapidjson/document.h> 14 #include <rapidjson/rapidjson.h> 15 #include <rapidjson/stringbuffer.h> 16 #include <rapidjson/writer.h> 23 #include <unordered_map> 35 static constexpr
const char *
name =
"AdaptedJsonSerializable";
36 static constexpr
const char *
qualifiedName =
"ReflectiveRapidJSON::AdaptedJsonSerializable";
42 namespace JsonReflector {
49 return size > std::numeric_limits<RAPIDJSON_NAMESPACE::SizeType>::max() ? std::numeric_limits<RAPIDJSON_NAMESPACE::SizeType>::max()
50 :
static_cast<RAPIDJSON_NAMESPACE::SizeType
>(size);
58 RAPIDJSON_NAMESPACE::StringBuffer buffer;
59 RAPIDJSON_NAMESPACE::Writer<RAPIDJSON_NAMESPACE::StringBuffer> writer(buffer);
60 document.Accept(writer);
69 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kObjectType);
70 const RAPIDJSON_NAMESPACE::ParseResult parseRes = document.Parse(json, jsonSize);
71 if (parseRes.IsError()) {
78 template <
typename Type>
79 using IsBuiltInType = Traits::Any<std::is_integral<Type>, std::is_floating_point<Type>, std::is_pointer<Type>, std::is_enum<Type>,
80 Traits::IsSpecializationOf<Type, std::tuple>, Traits::IsIteratable<Type>, Traits::IsSpecializationOf<Type, std::unique_ptr>,
81 Traits::IsSpecializationOf<Type, std::shared_ptr>, Traits::IsSpecializationOf<Type, std::weak_ptr>>;
82 template <
typename Type>
using IsCustomType = Traits::Not<IsBuiltInType<Type>>;
86 template <
typename Type>
91 template <
typename Type>
92 using IsMapOrHash = Traits::Any<Traits::IsSpecializationOf<Type, std::map>, Traits::IsSpecializationOf<Type, std::unordered_map>>;
93 template <
typename Type>
95 = Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>, Traits::Not<IsMapOrHash<Type>>>;
102 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
103 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
108 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>>...>
109 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
114 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>>...>
115 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
120 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>>...>
122 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
127 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>>...>
129 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
135 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
136 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);
141 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
142 inline void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
145 RAPIDJSON_NAMESPACE::Value::Object obj(value.GetObject());
146 push(reflectable, obj, allocator);
152 template <
typename Type, Traits::EnableIfAny<std::is_
integral<Type>, std::is_
floating_po
int<Type>>...>
153 inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
155 value.Set(reflectable, allocator);
161 template <
typename Type, Traits::EnableIfAny<std::is_enum<Type>>...>
162 inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
164 value.Set(
static_cast<Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type
>, uint64, int64>>(reflectable), allocator);
170 template <
typename Type, Traits::EnableIf<std::is_same<Type, const
char *>>...>
171 inline void push(Type 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, const
char *const &>>...>
180 inline void push(
const char *
const &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
182 value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), allocator);
188 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>>...>
189 inline void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
191 value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), allocator);
197 template <
typename Type, Traits::EnableIf<IsArray<Type>, Traits::HasSize<Type>>...>
198 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
201 RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray());
202 array.Reserve(reflectable.size(), allocator);
203 for (
const auto &item : reflectable) {
204 push(item, array, allocator);
211 template <
typename Type, Traits::EnableIf<IsArray<Type>, Traits::Not<Traits::HasSize<Type>>>...>
212 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
215 RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray());
216 for (
const auto &item : reflectable) {
217 push(item, array, allocator);
224 template <
typename Type, Traits::EnableIf<IsMapOrHash<Type>>...>
225 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
228 RAPIDJSON_NAMESPACE::Value::Object object(value.GetObject());
229 for (
const auto &item : reflectable) {
230 push(item.second, item.first.data(), object, allocator);
240 static void push(
const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
248 static void push(
const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
258 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::tuple>>...>
259 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
262 RAPIDJSON_NAMESPACE::Value::Array array(value.GetArray());
263 array.Reserve(std::tuple_size<Type>::value, allocator);
264 Detail::TuplePushHelper<Type, std::tuple_size<Type>::value>
::push(reflectable, array, allocator);
270 template <
typename Type,
271 Traits::EnableIfAny<Traits::IsSpecializationOf<Type, std::unique_ptr>, Traits::IsSpecializationOf<Type, std::shared_ptr>,
272 Traits::IsSpecializationOf<Type, std::weak_ptr>>...>
273 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
279 push(*reflectable, value, allocator);
285 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>>...>
286 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
288 RAPIDJSON_NAMESPACE::Value objectValue(RAPIDJSON_NAMESPACE::kObjectType);
289 RAPIDJSON_NAMESPACE::Value::Object object(objectValue.GetObject());
290 push(reflectable,
object, allocator);
291 value.PushBack(objectValue, allocator);
297 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>>...>
298 void push(
const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
300 RAPIDJSON_NAMESPACE::Value genericValue;
301 push(reflectable, genericValue, allocator);
302 value.PushBack(genericValue, allocator);
308 template <
typename Type, Traits::EnableIf<IsJsonSerializable<Type>>...>
310 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
312 RAPIDJSON_NAMESPACE::Value objectValue(RAPIDJSON_NAMESPACE::kObjectType);
313 RAPIDJSON_NAMESPACE::Value::Object object(objectValue.GetObject());
314 push(reflectable,
object, allocator);
315 value.AddMember(RAPIDJSON_NAMESPACE::StringRef(name), objectValue, allocator);
321 template <
typename Type, Traits::DisableIf<IsJsonSerializable<Type>>...>
323 const Type &reflectable,
const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
325 RAPIDJSON_NAMESPACE::Value genericValue;
326 push(reflectable, genericValue, allocator);
327 value.AddMember(RAPIDJSON_NAMESPACE::StringRef(name), genericValue, allocator);
336 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
337 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
338 JsonDeserializationErrors *errors);
343 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
344 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
349 template <
typename Type, Traits::EnableIf<IsArray<Type>, Traits::Not<Traits::IsReservable<Type>>>...>
350 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
355 template <
typename Type, Traits::EnableIf<IsArray<Type>, Traits::IsReservable<Type>>...>
356 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
361 template <
typename Type, Traits::EnableIf<IsArray<Type>>...>
362 void pull(Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstArray array, JsonDeserializationErrors *errors);
367 template <
typename Type, Traits::EnableIf<IsMapOrHash<Type>>...>
368 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
373 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::tuple>>...>
374 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
379 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::unique_ptr>>...>
380 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
385 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::shared_ptr>>...>
386 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
391 template <
typename Type>
393 Type &reflectable, rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ValueIterator &value, JsonDeserializationErrors *errors);
400 template <
typename Type>
401 inline void pull(Type &reflectable,
const char *name,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
402 JsonDeserializationErrors *errors);
407 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
408 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors);
413 template <
typename Type,
414 Traits::EnableIf<Traits::Not<std::is_same<Type, bool>>, Traits::Any<std::is_integral<Type>, std::is_floating_point<Type>>>...>
416 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors *errors)
418 if (!value.IsNumber()) {
424 reflectable = value.Is<Type>() ? value.Get<Type>() :
static_cast<Type
>(value.GetDouble());
430 template <
typename Type, Traits::EnableIf<std::is_same<Type,
bool>>...>
432 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors *errors)
434 if (!value.IsBool()) {
440 reflectable = value.GetBool();
447 template <
typename Type, Traits::EnableIfAny<std::is_enum<Type>>...>
449 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
451 using ExpectedType = Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, uint64, int64>;
452 if (!value.Is<ExpectedType>()) {
454 errors->reportTypeMismatch<ExpectedType>(value.GetType());
458 reflectable =
static_cast<Type
>(value.Get<ExpectedType>());
464 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>>...>
466 Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
468 if (!value.IsString()) {
470 errors->reportTypeMismatch<std::string>(value.GetType());
474 reflectable = value.GetString();
481 template <
typename Type, Traits::EnableIfAny<std::is_same<Type, const
char *>, std::is_same<Type, const
char *const &>>...>
482 inline void pull(Type &,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
484 if (!value.IsString()) {
486 errors->reportTypeMismatch<std::string>(value.GetType());
495 template <
typename Type, Traits::EnableIf<IsArray<Type>, Traits::Not<Traits::IsReservable<Type>>>...>
498 if (!value.IsArray()) {
504 pull(reflectable, value.GetArray(), errors);
510 template <
typename Type, Traits::EnableIf<IsArray<Type>, Traits::IsReservable<Type>>...>
513 if (!value.IsArray()) {
519 auto array = value.GetArray();
520 reflectable.reserve(array.Size());
521 pull(reflectable, array, errors);
527 template <
typename Type, Traits::EnableIf<IsArray<Type>>...>
534 std::size_t index = 0;
535 for (
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &item : array) {
540 reflectable.emplace_back();
541 pull(reflectable.back(), item, errors);
554 template <
typename Type, Traits::EnableIf<IsMapOrHash<Type>>...>
557 if (!value.IsObject()) {
563 auto obj = value.GetObject();
564 for (
auto i = obj.MemberBegin(), end = obj.MemberEnd(); i != end; ++i) {
565 pull(reflectable[i->name.GetString()], i->value, errors);
579 JsonReflector::pull<
typename std::tuple_element<N - 1, Tuple>::type>(std::get<N - 1>(tuple), value[N - 1], errors);
586 JsonReflector::pull<typename std::tuple_element<0, Tuple>::type>(std::get<0>(tuple), value[0], errors);
594 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::tuple>>...>
597 if (!value.IsArray()) {
603 auto array = value.GetArray();
604 if (array.Size() != std::tuple_size<Type>::value) {
611 Detail::TuplePullHelper<Type, std::tuple_size<Type>::value>
::pull(reflectable, array, errors);
617 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::unique_ptr>>...>
618 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
620 if (value.IsNull()) {
624 reflectable = std::make_unique<typename Type::element_type>();
625 pull(*reflectable, value, errors);
631 template <
typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::shared_ptr>>...>
632 void pull(Type &reflectable,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
634 if (value.IsNull()) {
638 reflectable = std::make_shared<typename Type::element_type>();
639 pull(*reflectable, value, errors);
645 template <
typename Type>
648 pull<Type>(reflectable, *value, errors);
657 template <
typename Type>
658 inline void pull(Type &reflectable,
const char *name,
const rapidjson::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
662 const auto member = value.FindMember(name);
663 if (member == value.MemberEnd()) {
668 const char *previousMember;
675 pull<Type>(reflectable, member->value, errors);
686 template <
typename Type, Traits::DisableIf<IsBuiltInType<Type>>...>
687 void pull(Type &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value,
JsonDeserializationErrors *errors)
689 if (!value.IsObject()) {
695 pull(reflectable, value.GetObject(), errors);
703 template <
typename Type, Traits::EnableIfAny<IsJsonSerializable<Type>, IsMapOrHash<Type>>...>
704 RAPIDJSON_NAMESPACE::StringBuffer
toJson(
const Type &reflectable)
706 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kObjectType);
707 RAPIDJSON_NAMESPACE::Document::Object object(document.GetObject());
708 push(reflectable,
object, document.GetAllocator());
715 template <
typename Type, Traits::EnableIfAny<std::is_
integral<Type>, std::is_
floating_po
int<Type>>...>
716 RAPIDJSON_NAMESPACE::StringBuffer
toJson(Type reflectable)
718 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kNumberType);
719 document.Set(reflectable, document.GetAllocator());
726 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>>...>
727 RAPIDJSON_NAMESPACE::StringBuffer
toJson(
const std::string &reflectable)
729 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kStringType);
730 document.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), document.GetAllocator());
737 template <
typename Type, Traits::EnableIf<std::is_same<Type, const
char *>>...> RAPIDJSON_NAMESPACE::StringBuffer
toJson(
const char *reflectable)
739 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kStringType);
740 document.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), document.GetAllocator());
747 template <
typename Type, Traits::EnableIf<IsArray<Type>>...> RAPIDJSON_NAMESPACE::StringBuffer
toJson(
const Type &reflectable)
749 RAPIDJSON_NAMESPACE::Document document(RAPIDJSON_NAMESPACE::kArrayType);
750 push(reflectable, document, document.GetAllocator());
759 template <
typename Type, Traits::EnableIfAny<IsJsonSerializable<Type>, IsMapOrHash<Type>>...>
763 if (!doc.IsObject()) {
771 pull<Type>(res, doc.GetObject(), errors);
778 template <
typename Type, Traits::EnableIfAny<std::is_
integral<Type>, std::is_
floating_po
int<Type>>...>
782 if (!doc.Is<Type>()) {
789 return doc.Get<Type>();
795 template <
typename Type, Traits::EnableIf<std::is_same<Type, std::
string>>...>
796 Type
fromJson(
const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors =
nullptr)
799 if (!doc.IsString()) {
806 return doc.GetString();
812 template <
typename Type, Traits::EnableIf<IsArray<Type>>...>
813 Type
fromJson(
const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors =
nullptr)
816 if (!doc.IsArray()) {
824 pull<Type>(res, doc.GetArray(), errors);
833 return fromJson<Type>(json, std::strlen(json), errors);
841 return fromJson<Type>(json.data(), json.size(), errors);
847 #endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H Contains helper for error handling when deserializing JSON files.
RAPIDJSON_NAMESPACE::StringBuffer serializeJsonDocToString(RAPIDJSON_NAMESPACE::Document &document)
Serializes the specified JSON document.
static void pull(Tuple &tuple, const RAPIDJSON_NAMESPACE::Value::ConstArray value, JsonDeserializationErrors *errors)
static void push(const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< IsMapOrHash< Type > >> IsArray
RAPIDJSON_NAMESPACE::Document parseJsonDocFromString(const char *json, std::size_t jsonSize)
Parses the specified JSON string.
The AdaptedJsonSerializable class allows considering 3rd party classes as serializable.
Traits::Any< Traits::Not< Traits::IsComplete< Type > >, std::is_base_of< JsonSerializable< Type >, Type >, AdaptedJsonSerializable< Type > > IsJsonSerializable
const char * currentMember
The name of the member (in currentRecord) which is currently being processed.
constexpr RAPIDJSON_NAMESPACE::SizeType rapidJsonSize(std::size_t size)
Casts the specified size to the size type used by RapidJSON ensuring no overflow happens.
static constexpr const char * qualifiedName
static void push(const Tuple &tuple, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
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...
static constexpr const char * name
std::size_t currentIndex
The index in the array which is currently processed.
Traits::Not< IsBuiltInType< Type > > IsCustomType
static void pull(Tuple &tuple, const RAPIDJSON_NAMESPACE::Value::ConstArray value, JsonDeserializationErrors *errors)
void reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType)
Reports a type mismatch between.
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
The TuplePullHelper class helps deserializing tuples from JSON arrays.
The TuplePushHelper class helps serializing tuples to JSON arrays.
static constexpr std::size_t noIndex
Indicates no array was being processed when the error occured.
Type fromJson(const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors=nullptr)
Deserializes the specified JSON to.
void reportArraySizeMismatch()
Reports an array size mismatch.
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.
Traits::Any< std::is_integral< Type >, std::is_floating_point< Type >, std::is_pointer< Type >, std::is_enum< Type >, Traits::IsSpecializationOf< Type, std::tuple >, Traits::IsIteratable< Type >, Traits::IsSpecializationOf< Type, std::unique_ptr >, Traits::IsSpecializationOf< Type, std::shared_ptr >, Traits::IsSpecializationOf< Type, std::weak_ptr > > IsBuiltInType
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.