Reflection for RapidJSON  0.0.15
Reflection for serializing/deserializing with RapidJSON
Namespaces | Classes | Typedefs | Enumerations | Functions
ReflectiveRapidJSON Namespace Reference

Namespaces

 BinaryReflector
 The BinaryReflector namespace contains BinaryReader and BinaryWriter for automatic binary (de)serialization.
 
 JsonReflector
 The JsonReflector namespace contains helper functions to ease the use of RapidJSON for automatic (de)serialization.
 

Classes

struct  AdaptedBinarySerializable
 The AdaptedBinarySerializable class allows considering 3rd party classes as serializable. More...
 
struct  AdaptedJsonSerializable
 The AdaptedJsonSerializable class allows considering 3rd party classes as serializable. More...
 
struct  BinarySerializable
 The BinarySerializable class provides the CRTP-base for (de)serializable objects. More...
 
struct  JsonDeserializationError
 The JsonDeserializationError struct describes any errors of fromJson() except such caused by invalid JSON. More...
 
struct  JsonDeserializationErrors
 The JsonDeserializationErrors struct can be passed to fromJson() for error handling. More...
 
struct  JsonSerializable
 The JsonSerializable class provides the CRTP-base for (de)serializable objects. More...
 
struct  TreatAsMapOrHash
 The TreatAsMapOrHash class allows treating custom classes as std::map or std::unordered_map. More...
 
struct  TreatAsMultiMapOrHash
 The TreatAsMultiMapOrHash class allows treating custom classes as std::multimap or std::unordered_multimap. More...
 
struct  TreatAsMultiSet
 The TreatAsMultiSet class allows treating custom classes as std::multiset or std::unordered_multiset. More...
 
struct  TreatAsSet
 The TreatAsSet class allows treating custom classes as std::set or std::unordered_set. More...
 

Typedefs

template<typename Type >
using IsMapOrHash = Traits::Any< Traits::IsSpecializationOf< Type, std::map >, Traits::IsSpecializationOf< Type, std::unordered_map >, TreatAsMapOrHash< Type > >
 
template<typename Type >
using IsMultiMapOrHash = Traits::Any< Traits::IsSpecializationOf< Type, std::multimap >, Traits::IsSpecializationOf< Type, std::unordered_multimap >, TreatAsMultiMapOrHash< Type > >
 
template<typename Type >
using IsSet = Traits::Any< Traits::IsSpecializationOf< Type, std::set >, Traits::IsSpecializationOf< Type, std::unordered_set >, TreatAsSet< Type > >
 
template<typename Type >
using IsMultiSet = Traits::Any< Traits::IsSpecializationOf< Type, std::multiset >, Traits::IsSpecializationOf< Type, std::unordered_multiset >, TreatAsMultiSet< Type > >
 
template<typename Type >
using IsArrayOrSet = Traits::Any< Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string_view > >, Traits::Not< IsMapOrHash< Type > >, Traits::Not< IsMultiMapOrHash< Type > >>, TreatAsSet< Type >, TreatAsMultiSet< Type > >
 
template<typename Type >
using IsArray = Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< IsMapOrHash< Type > >, Traits::Not< IsMultiMapOrHash< Type > >, Traits::Not< IsSet< Type > >, Traits::Not< IsMultiSet< Type > >>
 
template<typename Type >
using IsIteratableExceptString = Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >>
 
template<typename Type >
using IsVariant = Traits::All< Traits::IsSpecializationOf< Type, std::variant > >
 

Enumerations

enum  JsonDeserializationErrorKind : std::uint8_t {
  JsonDeserializationErrorKind::TypeMismatch, JsonDeserializationErrorKind::ArraySizeMismatch, JsonDeserializationErrorKind::ConversionError, JsonDeserializationErrorKind::UnexpectedDuplicate,
  JsonDeserializationErrorKind::InvalidVariantObject, JsonDeserializationErrorKind::InvalidVariantIndex
}
 The JsonDeserializationErrorKind enum specifies which kind of error happend when populating variables from parsing results. More...
 
enum  JsonType : std::uint8_t {
  JsonType::Null, JsonType::Number, JsonType::Bool, JsonType::String,
  JsonType::Array, JsonType::Object
}
 The JsonType enum specifies the JSON data type. More...
 

Functions

template<typename Type , Traits::EnableIf< std::is_base_of< JsonSerializable< Type >, Type >> * = nullptr>
JsonSerializable< Type > & as (Type &serializable)
 Helps to disambiguate when inheritance is used. More...
 
template<typename Type , Traits::EnableIf< std::is_base_of< JsonSerializable< Type >, Type >> * = nullptr>
const JsonSerializable< Type > & as (const Type &serializable)
 Helps to disambiguate when inheritance is used. More...
 
template<typename Type , Traits::EnableIf< Traits::Not< std::is_same< Type, bool >>, Traits::Any< std::is_integral< Type >, std::is_floating_point< Type >>> * = nullptr>
constexpr JsonType jsonType ()
 
constexpr JsonType jsonType (RAPIDJSON_NAMESPACE::Type type)
 Maps the type info provided by RapidJSON to JsonType. More...
 
constexpr JsonDeserializationErrors::ThrowOn operator| (JsonDeserializationErrors::ThrowOn lhs, JsonDeserializationErrors::ThrowOn rhs)
 Combines to ThrowOn values. More...
 
std::string_view jsonTypeToString (JsonType jsonType)
 
std::string formatJsonDeserializationError (const JsonDeserializationError &error)
 
 REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH (Foo)
 
 REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH (Foo)
 
 REFLECTIVE_RAPIDJSON_TREAT_AS_SET (Bar)
 
 REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET (Foo)
 

Typedef Documentation

◆ IsArray

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

Definition at line 62 of file traits.h.

◆ IsArrayOrSet

template<typename Type >
using ReflectiveRapidJSON::IsArrayOrSet = typedef Traits::Any< Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string> >, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string_view> >, Traits::Not<IsMapOrHash<Type> >, Traits::Not<IsMultiMapOrHash<Type> >>, TreatAsSet<Type>, TreatAsMultiSet<Type> >

Definition at line 57 of file traits.h.

◆ IsIteratableExceptString

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

Definition at line 65 of file traits.h.

◆ IsMapOrHash

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

Definition at line 46 of file traits.h.

◆ IsMultiMapOrHash

template<typename Type >
using ReflectiveRapidJSON::IsMultiMapOrHash = typedef Traits::Any<Traits::IsSpecializationOf<Type, std::multimap>, Traits::IsSpecializationOf<Type, std::unordered_multimap>, TreatAsMultiMapOrHash<Type> >

Definition at line 49 of file traits.h.

◆ IsMultiSet

template<typename Type >
using ReflectiveRapidJSON::IsMultiSet = typedef Traits::Any<Traits::IsSpecializationOf<Type, std::multiset>, Traits::IsSpecializationOf<Type, std::unordered_multiset>, TreatAsMultiSet<Type> >

Definition at line 54 of file traits.h.

◆ IsSet

template<typename Type >
using ReflectiveRapidJSON::IsSet = typedef Traits::Any<Traits::IsSpecializationOf<Type, std::set>, Traits::IsSpecializationOf<Type, std::unordered_set>, TreatAsSet<Type> >

Definition at line 52 of file traits.h.

◆ IsVariant

template<typename Type >
using ReflectiveRapidJSON::IsVariant = typedef Traits::All<Traits::IsSpecializationOf<Type, std::variant> >

Definition at line 67 of file traits.h.

Enumeration Type Documentation

◆ JsonDeserializationErrorKind

The JsonDeserializationErrorKind enum specifies which kind of error happend when populating variables from parsing results.

Enumerator
TypeMismatch 

The expected type does not match the type actually present in the JSON document.

ArraySizeMismatch 

The expected array size does not match the actual size of the JSON array. A fixed size is expected when deserializing an std::tuple.

ConversionError 

The expected type matches the type present in the JSON document, but further conversion of the value failed.

UnexpectedDuplicate 

The expected type matches the type present in the JSON document, but the value can not be added to the container because it is already present and duplicates are not allowed.

InvalidVariantObject 

The present object is supposed to represent an std::variant but lacks the index or data member.

InvalidVariantIndex 

The present variant index is not a number of outside of the expected range.

Definition at line 24 of file errorhandling.h.

◆ JsonType

enum ReflectiveRapidJSON::JsonType : std::uint8_t
strong

The JsonType enum specifies the JSON data type.

Remarks
This is currently only used for error handling to propagate expected and actual types in case of a mismatch.
Enumerator
Null 
Number 
Bool 
String 
Array 
Object 

Definition at line 37 of file errorhandling.h.

Function Documentation

◆ as() [1/2]

template<typename Type , Traits::EnableIf< std::is_base_of< JsonSerializable< Type >, Type >> * = nullptr>
const JsonSerializable<Type>& ReflectiveRapidJSON::as ( const Type &  serializable)

Helps to disambiguate when inheritance is used.

Definition at line 106 of file serializable.h.

◆ as() [2/2]

template<typename Type , Traits::EnableIf< std::is_base_of< JsonSerializable< Type >, Type >> * = nullptr>
JsonSerializable<Type>& ReflectiveRapidJSON::as ( Type &  serializable)

Helps to disambiguate when inheritance is used.

Definition at line 97 of file serializable.h.

◆ formatJsonDeserializationError()

std::string ReflectiveRapidJSON::formatJsonDeserializationError ( const JsonDeserializationError error)
inline

Definition at line 37 of file errorformatting.h.

◆ jsonType() [1/2]

template<typename Type , Traits::EnableIf< Traits::Not< std::is_same< Type, bool >>, Traits::Any< std::is_integral< Type >, std::is_floating_point< Type >>> * = nullptr>
constexpr JsonType ReflectiveRapidJSON::jsonType ( )
constexpr

Definition at line 50 of file errorhandling.h.

◆ jsonType() [2/2]

constexpr JsonType ReflectiveRapidJSON::jsonType ( RAPIDJSON_NAMESPACE::Type  type)
constexpr

Maps the type info provided by RapidJSON to JsonType.

Definition at line 87 of file errorhandling.h.

◆ jsonTypeToString()

std::string_view ReflectiveRapidJSON::jsonTypeToString ( JsonType  jsonType)
inline

Definition at line 17 of file errorformatting.h.

◆ operator|()

constexpr JsonDeserializationErrors::ThrowOn ReflectiveRapidJSON::operator| ( JsonDeserializationErrors::ThrowOn  lhs,
JsonDeserializationErrors::ThrowOn  rhs 
)
constexpr

Combines to ThrowOn values.

Definition at line 196 of file errorhandling.h.

◆ REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH()

ReflectiveRapidJSON::REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH ( Foo  )

◆ REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH()

ReflectiveRapidJSON::REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH ( Foo  )

◆ REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET()

ReflectiveRapidJSON::REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET ( Foo  )

◆ REFLECTIVE_RAPIDJSON_TREAT_AS_SET()

ReflectiveRapidJSON::REFLECTIVE_RAPIDJSON_TREAT_AS_SET ( Bar  )