Reflection for RapidJSON  0.0.3
Reflection for serializing/deserializing with RapidJSON
Namespaces | Typedefs | Functions
ReflectiveRapidJSON::JsonReflector Namespace Reference

The JsonReflector namespace contains helper functions to ease the use of RapidJSON for automatic (de)serialization. More...

Namespaces

 Detail
 

Typedefs

template<typename Type >
using IsBuiltInType = 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 > >
 
template<typename Type >
using IsCustomType = Traits::Not< IsBuiltInType< Type > >
 
template<typename Type >
using IsJsonSerializable = Traits::Any< Traits::Not< Traits::IsComplete< Type > >, std::is_base_of< JsonSerializable< Type >, Type >, AdaptedJsonSerializable< Type > >
 
template<typename Type >
using IsMapOrHash = Traits::Any< Traits::IsSpecializationOf< Type, std::map >, Traits::IsSpecializationOf< Type, std::unordered_map > >
 
template<typename Type >
using IsArray = Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< IsMapOrHash< Type > >>
 

Functions

constexpr RAPIDJSON_NAMESPACE::SizeType rapidJsonSize (std::size_t size)
 Casts the specified size to the size type used by RapidJSON ensuring no overflow happens. More...
 
RAPIDJSON_NAMESPACE::StringBuffer serializeJsonDocToString (RAPIDJSON_NAMESPACE::Document &document)
 Serializes the specified JSON document. More...
 
RAPIDJSON_NAMESPACE::Document parseJsonDocFromString (const char *json, std::size_t jsonSize)
 Parses the specified JSON string. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void push (const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified reflectable to the specified value. More...
 
template<typename Type , Traits::DisableIf< IsJsonSerializable< Type >> ...>
void push (const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the reflectable to the specified array. More...
 
template<typename Type , Traits::EnableIf< IsJsonSerializable< Type >> ...>
void push (const Type &reflectable, const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified reflectable which has custom type as a member to the specified object. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void push (const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the reflectable which has a custom type to the specified object. More...
 
template<typename Type , Traits::EnableIfAny< std::is_integral< Type >, std::is_floating_point< Type >> ...>
void push (Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified integer/float/boolean to the specified value. More...
 
template<typename Type , Traits::EnableIf< std::is_same< Type, const char *const &>> ...>
void push (const char *const &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified constant C-string to the specified value. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
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. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void pull (Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &value, JsonDeserializationErrors *errors)
 Pulls the reflectable which has a custom type from the specified value which is supposed and checked to contain an object. More...
 
template<typename Type , Traits::EnableIf< IsArray< Type >, Traits::Not< Traits::IsReservable< Type >>> ...>
void pull (Type &reflectable, const rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &value, JsonDeserializationErrors *errors)
 Pulls the specified reflectable which is an iteratable without reserve() method from the specified value which is checked to contain an array. More...
 
template<typename Type , Traits::EnableIf< IsArray< Type >> ...>
void pull (Type &reflectable, rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstArray array, JsonDeserializationErrors *errors)
 Pulls the specified reflectable which is an iteratable from the specified array. More...
 
template<typename Type >
void pull (Type &reflectable, rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ValueIterator &value, JsonDeserializationErrors *errors)
 Pulls the specified reflectable from the specified value iterator which is checked to contain the right type. More...
 
template<typename Type >
void pull (Type &reflectable, const char *name, const rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstObject &value, JsonDeserializationErrors *errors)
 Pulls the specified member of reflectable which has a custom type from the specified object. More...
 
template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >> ...>
RAPIDJSON_NAMESPACE::StringBuffer toJson (const Type &reflectable)
 Serializes the specified reflectable which has a custom type or can be mapped to and object. More...
 
template<typename Type , Traits::EnableIfAny< std::is_integral< Type >, std::is_floating_point< Type >> ...>
RAPIDJSON_NAMESPACE::StringBuffer toJson (Type reflectable)
 Serializes the specified reflectable which is an integer, float or boolean. More...
 
template<typename Type , Traits::EnableIf< std::is_same< Type, std::string >> ...>
RAPIDJSON_NAMESPACE::StringBuffer toJson (const std::string &reflectable)
 Serializes the specified reflectable which is an std::string. More...
 
template<typename Type , Traits::EnableIf< std::is_same< Type, const char *>> ...>
RAPIDJSON_NAMESPACE::StringBuffer toJson (const char *reflectable)
 Serializes the specified reflectable which is a C-string. More...
 
template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >> ...>
Type fromJson (const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors=nullptr)
 Deserializes the specified JSON to. More...
 
template<typename Type >
Type fromJson (const char *json, JsonDeserializationErrors *errors=nullptr)
 Deserializes the specified JSON from an null-terminated C-string to. More...
 
template<typename Type >
Type fromJson (const std::string &json, JsonDeserializationErrors *errors=nullptr)
 Deserializes the specified JSON from an std::string to. More...
 
template<>
void push< ChronoUtilities::DateTime > (const ChronoUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 
template<>
void push< ChronoUtilities::TimeSpan > (const ChronoUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 
template<>
void pull< ChronoUtilities::DateTime > (ChronoUtilities::DateTime &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &value, JsonDeserializationErrors *errors)
 
template<>
void pull< ChronoUtilities::TimeSpan > (ChronoUtilities::TimeSpan &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &value, JsonDeserializationErrors *errors)
 

Detailed Description

The JsonReflector namespace contains helper functions to ease the use of RapidJSON for automatic (de)serialization.

Typedef Documentation

◆ IsArray

template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsArray = typedef Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string> >, Traits::Not<IsMapOrHash<Type> >>

Definition at line 95 of file reflector.h.

◆ IsBuiltInType

template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsBuiltInType = typedef 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> >

Definition at line 81 of file reflector.h.

◆ IsCustomType

template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsCustomType = typedef Traits::Not<IsBuiltInType<Type> >

Definition at line 82 of file reflector.h.

◆ IsJsonSerializable

template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsJsonSerializable = typedef Traits::Any<Traits::Not<Traits::IsComplete<Type> >, std::is_base_of<JsonSerializable<Type>, Type>, AdaptedJsonSerializable<Type> >

Definition at line 88 of file reflector.h.

◆ IsMapOrHash

template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsMapOrHash = typedef Traits::Any<Traits::IsSpecializationOf<Type, std::map>, Traits::IsSpecializationOf<Type, std::unordered_map> >

Definition at line 92 of file reflector.h.

Function Documentation

◆ fromJson() [1/3]

template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >> ...>
Type ReflectiveRapidJSON::JsonReflector::fromJson ( const char *  json,
std::size_t  jsonSize,
JsonDeserializationErrors errors = nullptr 
)

Deserializes the specified JSON to.

Template Parameters
Typewhich is a custom type or can be mapped to an object.
Typewhich is an integer, float or boolean.
Typewhich is a std::string.
Typewhich can be mapped to an array.

Definition at line 760 of file reflector.h.

◆ fromJson() [2/3]

template<typename Type >
Type ReflectiveRapidJSON::JsonReflector::fromJson ( const char *  json,
JsonDeserializationErrors errors = nullptr 
)

Deserializes the specified JSON from an null-terminated C-string to.

Template Parameters
Type.

Definition at line 831 of file reflector.h.

◆ fromJson() [3/3]

template<typename Type >
Type ReflectiveRapidJSON::JsonReflector::fromJson ( const std::string &  json,
JsonDeserializationErrors errors = nullptr 
)

Deserializes the specified JSON from an std::string to.

Template Parameters
Type.

Definition at line 839 of file reflector.h.

◆ parseJsonDocFromString()

RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::parseJsonDocFromString ( const char *  json,
std::size_t  jsonSize 
)
inline

Parses the specified JSON string.

Definition at line 67 of file reflector.h.

◆ pull() [1/6]

template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::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.

Remarks
The definition of this function must be provided by the code generator or Boost.Hana.

Definition at line 40 of file reflector-boosthana.h.

◆ pull() [2/6]

template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::pull ( Type &  reflectable,
const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &  value,
JsonDeserializationErrors errors 
)
inline

Pulls the reflectable which has a custom type from the specified value which is supposed and checked to contain an object.

Checks whether the specified value contains a string.

Pulls the std::string from the specified value which is supposed and checked to contain a string.

Pulls the specified enumeration item from the specified value which is supposed and checked to be compatible with the underlying type.

Pulls the boolean from the specified value which is supposed and checked to contain the right type.

Pulls the integer or float from the specified value which is supposed and checked to contain the right type.

Remarks
It is not checked, whether value is actually a valid enum item.
Does not actually store the value since the ownership would not be clear (see README.md).

Definition at line 415 of file reflector.h.

◆ pull() [3/6]

template<typename Type , Traits::EnableIf< IsArray< Type >, Traits::Not< Traits::IsReservable< Type >>> ...>
void ReflectiveRapidJSON::JsonReflector::pull ( Type &  reflectable,
const rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &  value,
JsonDeserializationErrors errors 
)

Pulls the specified reflectable which is an iteratable without reserve() method from the specified value which is checked to contain an array.

Pulls the specified reflectable which is a shared_ptr from the specified value which might be null.

Pulls the specified reflectable which is a unique_ptr from the specified value which might be null.

Pulls the specified reflectable which is a tuple from the specified value which is checked to contain an array.

Pulls the specified reflectable which is a map from the specified value which is checked to contain an object.

Pulls the specified reflectable which is an iteratable with reserve() method from the specified value which is checked to contain an array.

Definition at line 496 of file reflector.h.

◆ pull() [4/6]

template<typename Type , Traits::EnableIf< IsArray< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::pull ( Type &  reflectable,
rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstArray  array,
JsonDeserializationErrors errors 
)

Pulls the specified reflectable which is an iteratable from the specified array.

The reflectable is cleared before.

Definition at line 528 of file reflector.h.

◆ pull() [5/6]

template<typename Type >
void ReflectiveRapidJSON::JsonReflector::pull ( Type &  reflectable,
rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ValueIterator &  value,
JsonDeserializationErrors errors 
)
inline

Pulls the specified reflectable from the specified value iterator which is checked to contain the right type.

Definition at line 646 of file reflector.h.

◆ pull() [6/6]

template<typename Type >
void ReflectiveRapidJSON::JsonReflector::pull ( Type &  reflectable,
const char *  name,
const rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstObject &  value,
JsonDeserializationErrors errors 
)
inline

Pulls the specified member of reflectable which has a custom type from the specified object.

Remarks
It is checked whether the object actually contains the member. If not, the missing member is ignored. So currently all members are optional.

Definition at line 658 of file reflector.h.

◆ pull< ChronoUtilities::DateTime >()

template<>
void ReflectiveRapidJSON::JsonReflector::pull< ChronoUtilities::DateTime > ( ChronoUtilities::DateTime &  reflectable,
const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &  value,
JsonDeserializationErrors errors 
)
inline

Definition at line 41 of file reflector-chronoutilities.h.

◆ pull< ChronoUtilities::TimeSpan >()

template<>
void ReflectiveRapidJSON::JsonReflector::pull< ChronoUtilities::TimeSpan > ( ChronoUtilities::TimeSpan &  reflectable,
const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &  value,
JsonDeserializationErrors errors 
)
inline

Definition at line 56 of file reflector-chronoutilities.h.

◆ push() [1/6]

template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::push ( const Type &  reflectable,
RAPIDJSON_NAMESPACE::Value &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)
inline

Pushes the specified reflectable to the specified value.

Pushes the specified unique_ptr, shared_ptr or weak_ptr to the specified value.

Pushes the specified tuple to the specified value.

Pushes the specified map (std::map, std::unordered_map) to the specified value.

Pushes the specified iteratable list (eg.

Pushes the specified iteratable (eg.

Pushes the specified std::string to the specified value.

Pushes the specified reflectable which has a custom type to the specified value.

std::vector, std::list) to the specified value.

Definition at line 142 of file reflector.h.

◆ push() [2/6]

template<typename Type , Traits::DisableIf< IsJsonSerializable< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::push ( const Type &  reflectable,
RAPIDJSON_NAMESPACE::Value::Array &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)

Pushes the reflectable to the specified array.

Pushes the specified reflectable to the specified array.

Pushes the specified reflectable which has a custom type to the specified array.

Pushes the reflectable which has a custom type to the specified array.

Definition at line 286 of file reflector.h.

◆ push() [3/6]

template<typename Type , Traits::EnableIf< IsJsonSerializable< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::push ( const Type &  reflectable,
const char *  name,
RAPIDJSON_NAMESPACE::Value::Object &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)

Pushes the specified reflectable which has custom type as a member to the specified object.

Pushes the specified reflectable as a member to the specified object.

Definition at line 309 of file reflector.h.

◆ push() [4/6]

template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::push ( const Type &  reflectable,
RAPIDJSON_NAMESPACE::Value::Object &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)

Pushes the reflectable which has a custom type to the specified object.

Remarks
The definition of this function must be provided by the code generator or Boost.Hana.

Definition at line 30 of file reflector-boosthana.h.

◆ push() [5/6]

template<typename Type , Traits::EnableIfAny< std::is_integral< Type >, std::is_floating_point< Type >> ...>
void ReflectiveRapidJSON::JsonReflector::push ( Type  reflectable,
RAPIDJSON_NAMESPACE::Value &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)
inline

Pushes the specified integer/float/boolean to the specified value.

Pushes the specified C-string to the specified value.

Pushes the specified enumeration item to the specified value.

Definition at line 153 of file reflector.h.

◆ push() [6/6]

template<typename Type , Traits::EnableIf< std::is_same< Type, const char *const &>> ...>
void ReflectiveRapidJSON::JsonReflector::push ( const char *const &  reflectable,
RAPIDJSON_NAMESPACE::Value &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)
inline

Pushes the specified constant C-string to the specified value.

Definition at line 180 of file reflector.h.

◆ push< ChronoUtilities::DateTime >()

template<>
void ReflectiveRapidJSON::JsonReflector::push< ChronoUtilities::DateTime > ( const ChronoUtilities::DateTime &  reflectable,
RAPIDJSON_NAMESPACE::Value &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)
inline

Definition at line 23 of file reflector-chronoutilities.h.

◆ push< ChronoUtilities::TimeSpan >()

template<>
void ReflectiveRapidJSON::JsonReflector::push< ChronoUtilities::TimeSpan > ( const ChronoUtilities::TimeSpan &  reflectable,
RAPIDJSON_NAMESPACE::Value &  value,
RAPIDJSON_NAMESPACE::Document::AllocatorType &  allocator 
)
inline

Definition at line 31 of file reflector-chronoutilities.h.

◆ rapidJsonSize()

constexpr RAPIDJSON_NAMESPACE::SizeType ReflectiveRapidJSON::JsonReflector::rapidJsonSize ( std::size_t  size)

Casts the specified size to the size type used by RapidJSON ensuring no overflow happens.

Definition at line 47 of file reflector.h.

◆ serializeJsonDocToString()

RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::serializeJsonDocToString ( RAPIDJSON_NAMESPACE::Document &  document)
inline

Serializes the specified JSON document.

Definition at line 56 of file reflector.h.

◆ toJson() [1/4]

template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >> ...>
RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::toJson ( const Type &  reflectable)

Serializes the specified reflectable which has a custom type or can be mapped to and object.

Serializes the specified reflectable which can be mapped to an array.

Definition at line 704 of file reflector.h.

◆ toJson() [2/4]

template<typename Type , Traits::EnableIfAny< std::is_integral< Type >, std::is_floating_point< Type >> ...>
RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::toJson ( Type  reflectable)

Serializes the specified reflectable which is an integer, float or boolean.

Definition at line 716 of file reflector.h.

◆ toJson() [3/4]

template<typename Type , Traits::EnableIf< std::is_same< Type, std::string >> ...>
RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::toJson ( const std::string &  reflectable)

Serializes the specified reflectable which is an std::string.

Definition at line 727 of file reflector.h.

◆ toJson() [4/4]

template<typename Type , Traits::EnableIf< std::is_same< Type, const char *>> ...>
RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::toJson ( const char *  reflectable)

Serializes the specified reflectable which is a C-string.

Definition at line 737 of file reflector.h.