1#ifndef REFLECTIVE_RAPIDJSON_JSON_SERIALIZABLE_H
2#define REFLECTIVE_RAPIDJSON_JSON_SERIALIZABLE_H
12#include <rapidjson/document.h>
23 void push(RAPIDJSON_NAMESPACE::Value &container);
24 void push(RAPIDJSON_NAMESPACE::Value &container,
const char *name);
27 RAPIDJSON_NAMESPACE::StringBuffer
toJson()
const;
33 static constexpr const char *
qualifiedName =
"ReflectiveRapidJSON::JsonSerializable";
35#if __cplusplus > 201707L
101template <
typename Type, Traits::EnableIf<std::is_base_of<JsonSerializable<Type>, Type>> * =
nullptr>
JsonSerializable<Type> &
as(Type &serializable)
109template <
typename Type, Traits::EnableIf<std::is_base_of<JsonSerializable<Type>, Type>> * =
nullptr>
122#define REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(T) \
123 template <> struct ReflectiveRapidJSON::AdaptedJsonSerializable<T> : Traits::Bool<true> {}
129#define REFLECTIVE_RAPIDJSON_PUSH_PRIVATE_MEMBERS(T) \
130 friend void ::ReflectiveRapidJSON::JsonReflector::push<T>( \
131 const T &reflectable, ::RAPIDJSON_NAMESPACE::Value::Object &value, ::RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
137#define REFLECTIVE_RAPIDJSON_PULL_PRIVATE_MEMBERS(T) \
138 friend void ::ReflectiveRapidJSON::JsonReflector::pull<T>(T & reflectable, \
139 const ::RAPIDJSON_NAMESPACE::GenericValue<::RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value, \
140 ::ReflectiveRapidJSON::JsonDeserializationErrors *errors)
146#define REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(T) \
147 REFLECTIVE_RAPIDJSON_PUSH_PRIVATE_MEMBERS(T); \
148 REFLECTIVE_RAPIDJSON_PULL_PRIVATE_MEMBERS(T)
Contains functions to (de)serialize basic types such as int, double, bool, std::string,...
RAPIDJSON_NAMESPACE::StringBuffer toJson(const Type &reflectable)
Serializes the specified reflectable.
Type fromJson(const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors=nullptr)
Deserializes the specified JSON to.
void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Pushes the specified reflectable to the specified value.
RAPIDJSON_NAMESPACE::Document toJsonDocument(const Type &reflectable)
Serializes the specified reflectable which has a custom type or can be mapped to and object.
JsonSerializable< Type > & as(Type &serializable)
Helps to disambiguate when inheritance is used.
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
The JsonSerializable class provides the CRTP-base for (de)serializable objects.
RAPIDJSON_NAMESPACE::StringBuffer toJson() const
Converts the object to its JSON representation (rapidjson::StringBuffer).
static Type fromJson(const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors=nullptr)
Constructs a new object from the specified JSON.
void push(RAPIDJSON_NAMESPACE::Value &container)
Pushes the object to the specified RapidJSON array.
RAPIDJSON_NAMESPACE::Document toJsonDocument() const
Converts the object to its JSON representation (rapidjson::Document).
static constexpr const char * qualifiedName