JSON complex object mapper. More...
#include <mapper.hpp>
Public Member Functions | |
| ObjectMapper (const ObjectMapper &other)=delete | |
| ObjectMapper (ObjectMapper &&other)=delete | |
| void | serializeValue (const T &value, anch::json::WriterContext &context) const |
| bool | deserializeValue (T &value, anch::json::ReaderContext &context) const |
| template<typename P, typename... C> requires (anch::val::FieldConstraint<C,P> && ...) | |
| ObjectMapper< T > & | registerField (const std::string &key, P T::*value, C &&... constraints) |
| template<typename P, typename... C> requires (anch::val::FieldConstraint<C,P> && ...) | |
| ObjectMapper< T > & | registerField (const std::string &key, std::function< P(const T &)> getter, const C &... constraints) |
| template<typename P, typename... C> requires (anch::val::FieldConstraint<C,P> && ...) | |
| ObjectMapper< T > & | registerField (const std::string &key, std::function< void(T &, const P &)> setter, C &&... constraints) |
| template<typename P, typename... C> requires (anch::val::FieldConstraint<C,P> && ...) | |
| ObjectMapper< T > & | registerField (const std::string &key, std::function< P(const T &)> getter, std::function< void(T &, const P &)> setter, C &&... constraints) |
| Public Member Functions inherited from anch::json::GenericMapper< ObjectMapper< T >, T > | |
| void | serialize (const T &value, anch::json::WriterContext &context) const |
| bool | deserialize (T &value, anch::json::ReaderContext &context) const |
Friends | |
| class | anch::json::Factory< T > |
Additional Inherited Members | |
| Protected Member Functions inherited from anch::json::GenericMapper< ObjectMapper< T >, T > | |
| GenericMapper () | |
| virtual | ~GenericMapper () |
JSON complex object mapper.
This is a generic template header implementation.
Type has to be a class or a structure described by an anch::Mapping specialization (anch-utils, mapping.hpp ): its registerObject function registers the fields on this mapper. Fields of std::optional , smart pointers, collections and maps are mapped with the mapper of their value type.
Field constraints ( anch::val::Required , value constraints like anch::val::MinLength , see anch-val, val/constraints.hpp ) can be given at registration. They are checked on deserialization ( deserialize_check_constraints option, enabled by default) and on serialization ( serialize_check_constraints option, disabled by default).
Errors raised while deserializing or serializing a field value have this field in their path ( MappingError::getPath ).
| T | the object type |
|
delete |
Forbids ObjectMapper copy constructor
|
delete |
Forbids ObjectMapper move constructor
| bool anch::json::ObjectMapper< T >::deserializeValue | ( | T & | value, |
| anch::json::ReaderContext & | context ) const |
Deserialize JSON
| value | the value to write in |
| context | the mapper context |
false when null found, true otherwise | ObjectMapper< T > & anch::json::ObjectMapper< T >::registerField | ( | const std::string & | key, |
| P T::* | value, | ||
| C &&... | constraints ) |
Register mapping by field
| P | the parameter type |
| C | the constraints types |
| key | the JSON key |
| value | the JSON value in object |
| constraints | the field constraints ( anch::val::required , anch::val::minLength , ...) |
this | ObjectMapper< T > & anch::json::ObjectMapper< T >::registerField | ( | const std::string & | key, |
| std::function< P(const T &)> | getter, | ||
| const C &... | constraints ) |
Register mapping by field
| P | the parameter type |
| C | the constraints types |
| key | the JSON key |
| getter | the JSON value getter function |
| constraints | the field constraints, checked on serialization |
this | ObjectMapper< T > & anch::json::ObjectMapper< T >::registerField | ( | const std::string & | key, |
| std::function< P(const T &)> | getter, | ||
| std::function< void(T &, const P &)> | setter, | ||
| C &&... | constraints ) |
Register mapping by field
| P | the parameter type |
| C | the constraints types |
| key | the JSON key |
| getter | the JSON value getter function |
| setter | the JSON value setter function |
| constraints | the field constraints ( anch::val::required , anch::val::minLength , ...), checked on deserialization |
this | ObjectMapper< T > & anch::json::ObjectMapper< T >::registerField | ( | const std::string & | key, |
| std::function< void(T &, const P &)> | setter, | ||
| C &&... | constraints ) |
Register mapping by field
| P | the parameter type |
| C | the constraints types |
| key | the JSON key |
| setter | the JSON value setter function |
| constraints | the field constraints ( anch::val::required , anch::val::minLength , ...) |
this | void anch::json::ObjectMapper< T >::serializeValue | ( | const T & | value, |
| anch::json::WriterContext & | context ) const |
Serialize value
| value | the reference attribute to serialize |
| context | the writer context |