AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
anch::json Namespace Reference

JSON namespace. More...

Classes

class  Factory
 JSON mapper factory. More...
 
class  JSONItem
 
class  JSONMapper
 JSON mapper with mapping options. More...
 
class  MappingError
 Mapping error. More...
 
struct  MappingOptions
 JSON mapping options. More...
 
class  ObjectMapper
 JSON complex object mapper. More...
 
class  PrimitiveMapper
 JSON primitive types mapper. More...
 
class  Reader
 JSON reader based on events. More...
 
class  ReaderContext
 JSON mapper context. More...
 

Typedefs

using LexFunc = std::function<bool(anch::json::ReaderContext&)>
 
using AddItem = std::function<bool(anch::json::ReaderContext&)>
 
using PushItem = std::function<void(const std::string&, anch::json::ReaderContext&)>
 
using jint = int64_t
 
using juint = uint64_t
 
using jfloat = long double
 
template<typename T>
using SerializeFn = std::function<void(const T&, std::ostream&, const anch::json::MappingOptions&)>
 
template<typename T>
using DeserializeFn = std::function<bool(T&, anch::json::ReaderContext&)>
 

Enumerations

enum class  ErrorCode { INVALID_FORMAT = 0 , UNEXPECTED_FIELD , POTENTIAL_OVERFLOW , UNKNOWN = 9999 }
 
enum class  EventType {
  VNULL = 0 , TRUE , FALSE , FIELD ,
  NUMBER , STRING , BEGIN_OBJECT , END_OBJECT ,
  BEGIN_ARRAY , END_ARRAY
}
 

Functions

template<typename T>
constexpr bool isPrimitive ()
 Check if type is a primitive JSON type.
 
template<typename T>
void registerObject (anch::json::ObjectMapper< T > &mapper)
 
template<typename T>
void serialize (const T &value, std::ostream &out, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void serialize (const std::vector< T > &value, std::ostream &out, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void serialize (const std::list< T > &value, std::ostream &out, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void serialize (const std::set< T > &value, std::ostream &out, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
std::string serialize (const T &value, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
std::string serialize (const std::vector< T > &value, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
std::string serialize (const std::list< T > &value, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
std::string serialize (const std::set< T > &value, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void deserialize (T &value, std::istream &input, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
deserialize (std::istream &input, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void deserialize (std::vector< T > &values, std::istream &input, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void deserialize (std::list< T > &values, std::istream &input, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
template<typename T>
void deserialize (std::set< T > &values, std::istream &input, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
 
void lexTrue (anch::json::ReaderContext &context)
 
void lexFalse (anch::json::ReaderContext &context)
 
bool lexBoolean (bool &value, anch::json::ReaderContext &context)
 
void parseDecimal (anch::json::ReaderContext &context)
 
bool lexInteger (anch::json::jint &value, anch::json::ReaderContext &context)
 
bool lexUInteger (anch::json::juint &value, anch::json::ReaderContext &context)
 
void parseNumber (anch::json::ReaderContext &context)
 
bool lexNumber (double &value, anch::json::ReaderContext &context)
 
void lexStringContent (anch::json::ReaderContext &context)
 
bool lexString (std::string &value, anch::json::ReaderContext &context)
 
bool lexField (std::string &field, anch::json::ReaderContext &context)
 
char discardFail (anch::json::ReaderContext &context)
 
char lexDiscard (anch::json::ReaderContext &context)
 
void lexNull (anch::json::ReaderContext &context)
 
bool objectHasValueLex (anch::json::ReaderContext &context)
 
void lexObject (const std::map< std::string, anch::json::LexFunc > &readers, std::set< std::string > &fields, anch::json::ReaderContext &context)
 
void lexArray (anch::json::AddItem addFunc, anch::json::ReaderContext &context)
 
void lexMap (anch::json::PushItem pushFunc, anch::json::ReaderContext &context)
 
void lexUnknown (anch::json::ReaderContext &context)
 
void lexUnknownFail (anch::json::ReaderContext &context)
 
void serializeFieldName (std::ostream &out, const std::optional< std::string > &field)
 
void serializeFieldName (std::ostream &out, const std::string &field)
 
template<typename T>
bool serialize (const T &value, std::ostream &out, anch::json::SerializeFn< T > serializeFunc, const anch::json::MappingOptions &options, const std::optional< std::string > &field)
 
bool serializeNull (std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field)
 
template<typename T>
bool serialize (const T *const value, std::ostream &out, anch::json::SerializeFn< T > serializeFunc, const anch::json::MappingOptions &options, const std::optional< std::string > &field)
 
template<typename T>
bool serialize (const std::optional< T > &value, std::ostream &out, anch::json::SerializeFn< T > serializeFunc, const anch::json::MappingOptions &options, const std::optional< std::string > &field)
 
template<typename T, typename A>
void serializeArray (const A &array, std::ostream &out, anch::json::DeserializeFn< T > serializeFunc, const anch::json::MappingOptions &options, const std::optional< std::string > &field)
 
template<typename T>
void serializeMap (const std::map< std::string, T > &map, std::ostream &out, anch::json::SerializeFn< T > serializeFunc, const anch::json::MappingOptions &options, const std::optional< std::string > &field)
 
template<typename T>
void deserialize (T &value, anch::json::ReaderContext &context, anch::json::DeserializeFn< T > deserializeFunc)
 
template<typename T>
void deserialize (T *value, anch::json::ReaderContext &context, anch::json::DeserializeFn< T > deserializeFunc)
 
template<typename T>
void deserialize (std::optional< T > &value, anch::json::ReaderContext &context, anch::json::DeserializeFn< T > deserializeFunc)
 
template<typename T>
bool addToVector (std::vector< T > &value, anch::json::DeserializeFn< T > deser, anch::json::ReaderContext &context)
 
template<typename T>
bool addToList (std::list< T > &value, anch::json::DeserializeFn< T > deser, anch::json::ReaderContext &context)
 
template<typename T>
bool addToSet (std::set< T > &value, anch::json::DeserializeFn< T > deser, anch::json::ReaderContext &context)
 
template<typename T>
void deserializeMap (std::function< void(const std::pair< std::string, T > &)> pushFunc, anch::json::ReaderContext &context, anch::json::DeserializeFn< T > deserializeFunc)
 

Variables

const char STRING_DELIMITER = '"'
 
const char FIELD_SEPARATOR = ','
 
const char FIELD_VALUE_SEPARATOR = ':'
 
const char OBJECT_BEGIN = '{'
 
const char OBJECT_END = '}'
 
const char ARRAY_BEGIN = '['
 
const char ARRAY_END =']'
 
const std::optional< std::string > EMPTY_FIELD
 
MappingOptions DEFAULT_MAPPING_OPTIONS
 

Detailed Description

JSON namespace.

Provides serialization and deserialization functions for JSON format.

Typedef Documentation

◆ AddItem

using anch::json::AddItem = std::function<bool(anch::json::ReaderContext&)>

Parse and add item to array function (return true when ']' has been found, false otherwise)

◆ DeserializeFn

template<typename T>
using anch::json::DeserializeFn = std::function<bool(T&, anch::json::ReaderContext&)>

Deserialization function definition

◆ jfloat

using anch::json::jfloat = long double

Maximum float precision declaration

◆ jint

using anch::json::jint = int64_t

Maximum signed integer precision declaration

◆ juint

using anch::json::juint = uint64_t

Maximum unsigned integer precision declaration

◆ LexFunc

using anch::json::LexFunc = std::function<bool(anch::json::ReaderContext&)>

Object lexer function

◆ PushItem

using anch::json::PushItem = std::function<void(const std::string&, anch::json::ReaderContext&)>

Parse and insert item to map

◆ SerializeFn

template<typename T>
using anch::json::SerializeFn = std::function<void(const T&, std::ostream&, const anch::json::MappingOptions&)>

Serialization function definition

Enumeration Type Documentation

◆ ErrorCode

enum class anch::json::ErrorCode
strong

JSON mapping error code

Author
Vincent Lachenal
Since
0.1
Enumerator
INVALID_FORMAT 

Invalid format

UNEXPECTED_FIELD 

Found unexpected field (and parsing options disallow it)

POTENTIAL_OVERFLOW 

Found too many space characters or charcters in field name (according to parsing option)

UNKNOWN 

Unexpected error code

◆ EventType

enum class anch::json::EventType
strong

Reader found element type

Author
Vincent Lachenal
Since
0.1
Enumerator
VNULL 

'null' value (no value)

TRUE 

Boolean 'true' value (no value)

FALSE 

Boolean 'false' value (no value)

FIELD 

Field value (value stored as std::string)

NUMBER 

Number value (value stored as double)

STRING 

String value (value as stored std::string)

BEGIN_OBJECT 

Begin object (no value)

END_OBJECT 

End object (no value)

BEGIN_ARRAY 

Begin array (no value)

END_ARRAY 

End array (no value)

Function Documentation

◆ addToList()

template<typename T>
bool anch::json::addToList ( std::list< T > & value,
anch::json::DeserializeFn< T > deser,
anch::json::ReaderContext & context )

Deserialize item and add it to list if not null

Parameters
valuethe list to add in
deserthe deserialization function
contextthe reader context

◆ addToSet()

template<typename T>
bool anch::json::addToSet ( std::set< T > & value,
anch::json::DeserializeFn< T > deser,
anch::json::ReaderContext & context )

Deserialize item and add it to set if not null

Parameters
valuethe set to add in
deserthe deserialization function
contextthe reader context

◆ addToVector()

template<typename T>
bool anch::json::addToVector ( std::vector< T > & value,
anch::json::DeserializeFn< T > deser,
anch::json::ReaderContext & context )

Deserialize item and add it to vector if not null

Parameters
valuethe vector to add in
deserthe deserialization function
contextthe reader context

◆ deserialize() [1/8]

template<typename T>
T anch::json::deserialize ( std::istream & input,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Deserialize object

Template Parameters
Tthe object type
Parameters
inputthe input stream to parse
optionsthe options to use
Returns
the deserialized object by copy

◆ deserialize() [2/8]

template<typename T>
void anch::json::deserialize ( std::list< T > & values,
std::istream & input,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Deserialize objects

Template Parameters
Tthe object type
Parameters
valuesthe values to fill
inputthe input stream to parse
optionsthe options to use

◆ deserialize() [3/8]

template<typename T>
void anch::json::deserialize ( std::optional< T > & value,
anch::json::ReaderContext & context,
anch::json::DeserializeFn< T > deserializeFunc )

Deserialize JSON value

Parameters
valuethe value to fill
contextthe mapping context
deserializeFuncthe value deserialization function

◆ deserialize() [4/8]

template<typename T>
void anch::json::deserialize ( std::set< T > & values,
std::istream & input,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Deserialize objects

Template Parameters
Tthe object type
Parameters
valuesthe values to fill
inputthe input stream to parse
optionsthe options to use

◆ deserialize() [5/8]

template<typename T>
void anch::json::deserialize ( std::vector< T > & values,
std::istream & input,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Deserialize objects

Template Parameters
Tthe object type
Parameters
valuesthe values to fill
inputthe input stream to parse
optionsthe options to use

◆ deserialize() [6/8]

template<typename T>
void anch::json::deserialize ( T & value,
anch::json::ReaderContext & context,
anch::json::DeserializeFn< T > deserializeFunc )

Deserialize JSON value

Parameters
valuethe value to fill
contextthe mapping context
deserializeFuncthe value deserialization function

◆ deserialize() [7/8]

template<typename T>
void anch::json::deserialize ( T & value,
std::istream & input,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Deserialize object

Template Parameters
Tthe object type
Parameters
valuethe value to fill
inputthe input stream to parse
optionsthe options to use

◆ deserialize() [8/8]

template<typename T>
void anch::json::deserialize ( T * value,
anch::json::ReaderContext & context,
anch::json::DeserializeFn< T > deserializeFunc )

Deserialize JSON value

Parameters
valuethe value to fill
contextthe mapping context
deserializeFuncthe value deserialization function

◆ deserializeMap()

template<typename T>
void anch::json::deserializeMap ( std::function< void(const std::pair< std::string, T > &)> pushFunc,
anch::json::ReaderContext & context,
anch::json::DeserializeFn< T > deserializeFunc )

JSON array deserialization generic implementation

Template Parameters
Tthe object type
Parameters
pushFuncthe push function according to container type
contextthe mapping context
deserializeFuncthe value deserialization function

JSON map deserialization generic implementation

Template Parameters
Tthe object type
Parameters
contextthe mapping context
pushFuncthe push function according to container type
deserializeFuncthe value deserialization function

◆ discardFail()

char anch::json::discardFail ( anch::json::ReaderContext & context)

Fail on any discardable character

Parameters
contextthe parser context
Returns
the not discardable character
Exceptions
anch::json::MappingErrordiscardable charater has been found

◆ isPrimitive()

template<typename T>
bool anch::json::isPrimitive ( )
constexpr

Check if type is a primitive JSON type.

When not specialzed, the function always return false .
Every C basic types are defined as primitive. std::string and std::string_view are also defined as primitive.

You can declare any type as primitive with template function specialization.

Template Parameters
Tthe type to check
Returns
true if type is a JSON primitive type, false otherwise

◆ lexArray()

void anch::json::lexArray ( anch::json::AddItem addFunc,
anch::json::ReaderContext & context )

Parse array

Parameters
addFuncparse and add elem to array function
contextthe context
Exceptions
anch::json::MappingErrorparsing error

◆ lexBoolean()

bool anch::json::lexBoolean ( bool & value,
anch::json::ReaderContext & context )

Boolean value lexer.
Possible values are: null, true and false

Parameters
valuethe boolean value to store in (not set when null has been found)
contextthe parser context
Returns
false when null , true otherwise
Exceptions
anch::json::MappingErrorparsing error

◆ lexDiscard()

char anch::json::lexDiscard ( anch::json::ReaderContext & context)

Consume stream until unescapable character

Parameters
contextthe parser context
Returns
the not discardable character
Exceptions
anch::json::MappingErrormaximum number of discardable charater has been reached

◆ lexFalse()

void anch::json::lexFalse ( anch::json::ReaderContext & context)

'false' value lexer.

Parameters
contextthe parser context
Exceptions
anch::json::MappingErrorparsing error

◆ lexField()

bool anch::json::lexField ( std::string & field,
anch::json::ReaderContext & context )

Field lexer function.
This lexer will look for " character to begin and end with ".
If begin character is not found, field will be empty.
If " end character is not found (according to options and stream), it will raised exception

Parameters
fieldthe field to fill when found
contextthe parser context
Returns
true when found, false otherwise
Exceptions
anch::json::MappingErrorparsing error

◆ lexInteger()

bool anch::json::lexInteger ( anch::json::jint & value,
anch::json::ReaderContext & context )

Signed integer value lexer.
Possible values are: null and signed integer

Parameters
valuethe signed value to store in (not set when null has been found)
contextthe parser context
Returns
false when null , true otherwise
Exceptions
anch::json::MappingErrorparsing error

◆ lexMap()

void anch::json::lexMap ( anch::json::PushItem pushFunc,
anch::json::ReaderContext & context )

Parse map

Parameters
pushFuncparse and add elem to map function
contextthe context
Exceptions
anch::json::MappingErrorparsing error

◆ lexNull()

void anch::json::lexNull ( anch::json::ReaderContext & context)

'null' value lexer.

Parameters
contextthe parser context
Exceptions
anch::json::MappingErrorparsing error

◆ lexNumber()

bool anch::json::lexNumber ( double & value,
anch::json::ReaderContext & context )

Floating integer (double) value lexer.
Possible values are: null and floating integer value (can parse exponential representation).

Parameters
valuethe value to write in (not set when null has been found)
contextthe parser context
Returns
false when null , true otherwise
Exceptions
anch::json::MappingErrorparsing error

◆ lexObject()

void anch::json::lexObject ( const std::map< std::string, anch::json::LexFunc > & readers,
std::set< std::string > & fields,
anch::json::ReaderContext & context )

Object lexer function.

Parameters
readersthe declared fields and their reader function
fieldsthe found fields to register in
contextthe parser context
Exceptions
anch::json::MappingErrorparsing error

◆ lexString()

bool anch::json::lexString ( std::string & value,
anch::json::ReaderContext & context )

String lexer function.
This lexer will look for " character to begin and end with ".
If begin character is not found, field will be empty.
If " end character is not found (according to options and stream), it will raised exception

Parameters
valuethe string value to fill when found
contextthe parser context
Returns
false when null has been found, true otherwise
Exceptions
anch::json::MappingErrorparsing error

◆ lexStringContent()

void anch::json::lexStringContent ( anch::json::ReaderContext & context)

Lex string content (between the '"').
The result will be stored in the context buffer.

Parameters
contextthe JSON context

◆ lexTrue()

void anch::json::lexTrue ( anch::json::ReaderContext & context)

'true' value lexer.

Parameters
contextthe parser context
Exceptions
anch::json::MappingErrorparsing error

◆ lexUInteger()

bool anch::json::lexUInteger ( anch::json::juint & value,
anch::json::ReaderContext & context )

Unsigned integer value lexer.
Possible values are: null and unsigned integer (min value is always 0)

Parameters
valuethe unsigned value to store in (not set when null has been found)
contextthe parser context
Returns
false when null , true otherwise
Exceptions
anch::json::MappingErrorparsing error

◆ lexUnknown()

void anch::json::lexUnknown ( anch::json::ReaderContext & context)

Parse unknown field value

Parameters
contextthe context
Exceptions
anch::json::MappingErrorparsing error

◆ lexUnknownFail()

void anch::json::lexUnknownFail ( anch::json::ReaderContext & context)

Raise anch::json::MappingError

Parameters
contextthe context
Exceptions
anch::json::MappingErrorparsing error

◆ objectHasValueLex()

bool anch::json::objectHasValueLex ( anch::json::ReaderContext & context)

Check if object has value (start with '{') or is null

Parameters
contextthe parser context
Returns
object has value
Exceptions
anch::json::MappingErrorparsing error

◆ parseDecimal()

void anch::json::parseDecimal ( anch::json::ReaderContext & context)

Parse decimale digits and store them to context value's buffer

Parameters
contextthe context

◆ parseNumber()

void anch::json::parseNumber ( anch::json::ReaderContext & context)

Parse float.
End parsing at first unrecognized character.

Parameters
contextthe parser context

◆ registerObject()

template<typename T>
void anch::json::registerObject ( anch::json::ObjectMapper< T > & mapper)

Fields registry function
This function has to be specialized for each class/structure which has to be serialized/deserialized.

Template Parameters
Tthe object type
Parameters
mapperthe ObjectMapper to use

◆ serialize() [1/11]

template<typename T>
std::string anch::json::serialize ( const std::list< T > & value,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize objects

Template Parameters
Tthe object type
Parameters
valuethe object to serialize
optionsthe options to use
Returns
the serialized objects as std::string

◆ serialize() [2/11]

template<typename T>
void anch::json::serialize ( const std::list< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize objects

Template Parameters
Tthe object type
Parameters
valuethe objects to serialize
outthe output stream to write in
optionsthe options to use

◆ serialize() [3/11]

template<typename T>
bool anch::json::serialize ( const std::optional< T > & value,
std::ostream & out,
anch::json::SerializeFn< T > serializeFunc,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field )

Serialize JSON optional value

Template Parameters
theobject type
Parameters
valuethe value to serialize
outthe output stream to write in
serializeFuncthe serialization function
optionsthe options to use
fieldthe optional field name

◆ serialize() [4/11]

template<typename T>
std::string anch::json::serialize ( const std::set< T > & value,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize objects

Template Parameters
Tthe object type
Parameters
valuethe object to serialize
optionsthe options to use
Returns
the serialized objects as std::string

◆ serialize() [5/11]

template<typename T>
void anch::json::serialize ( const std::set< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize objects

Template Parameters
Tthe object type
Parameters
valuethe objects to serialize
outthe output stream to write in
optionsthe options to use

◆ serialize() [6/11]

template<typename T>
std::string anch::json::serialize ( const std::vector< T > & value,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize objects

Template Parameters
Tthe object type
Parameters
valuethe object to serialize
optionsthe options to use
Returns
the serialized objects as std::string

◆ serialize() [7/11]

template<typename T>
void anch::json::serialize ( const std::vector< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize objects

Template Parameters
Tthe object type
Parameters
valuethe objects to serialize
outthe output stream to write in
optionsthe options to use

◆ serialize() [8/11]

template<typename T>
std::string anch::json::serialize ( const T & value,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize object

Template Parameters
Tthe object type
Parameters
valuethe object to serialize
optionsthe options to use
Returns
the serialized object as std::string

◆ serialize() [9/11]

template<typename T>
bool anch::json::serialize ( const T & value,
std::ostream & out,
anch::json::SerializeFn< T > serializeFunc,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field )

Serialize JSON value

Template Parameters
theobject type
Parameters
valuethe value to serialize
outthe output stream to write in
serializeFuncthe serialization function
optionsthe options to use
fieldthe optional field name

◆ serialize() [10/11]

template<typename T>
void anch::json::serialize ( const T & value,
std::ostream & out,
const anch::json::MappingOptions & options = anch::json::DEFAULT_MAPPING_OPTIONS )

Serialize object

Template Parameters
Tthe object type
Parameters
valuethe object to serialize
outthe output stream to write in
optionsthe options to use

◆ serialize() [11/11]

template<typename T>
bool anch::json::serialize ( const T *const value,
std::ostream & out,
anch::json::SerializeFn< T > serializeFunc,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field )

Serialize JSON pointer value

Template Parameters
theobject type
Parameters
valuethe value to serialize
outthe output stream to write in
serializeFuncthe serialization function
optionsthe options to use
fieldthe optional field name

◆ serializeArray()

template<typename T, typename A>
void anch::json::serializeArray ( const A & array,
std::ostream & out,
anch::json::DeserializeFn< T > serializeFunc,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field )

JSON array deserialization generic implementation

Template Parameters
Athe container type
Tthe object type
Parameters
arraythe array to serialize
outthe output stream to write in
serializeFuncthe serialization function
optionsthe options to use
fieldthe optional field name

◆ serializeFieldName() [1/2]

void anch::json::serializeFieldName ( std::ostream & out,
const std::optional< std::string > & field )

Serialize field name according to value

Parameters
outthe ouput stream to write in
fieldthe optional field name to serialize (or not)

◆ serializeFieldName() [2/2]

void anch::json::serializeFieldName ( std::ostream & out,
const std::string & field )

Serialize field name

Parameters
outthe ouput stream to write in
fieldthe field name to serialize

◆ serializeMap()

template<typename T>
void anch::json::serializeMap ( const std::map< std::string, T > & map,
std::ostream & out,
anch::json::SerializeFn< T > serializeFunc,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field )

JSON map deserialization generic implementation

Template Parameters
Tthe object type
Parameters
mapthe map to serialize
outthe output stream to write in
serializeFuncthe serialization function
optionsthe options to use
fieldthe optional field name

◆ serializeNull()

bool anch::json::serializeNull ( std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field )

Serialize unset value according to options

Parameters
outthe output stream to write in
optionsthe options to use
fieldthe optional field name

Variable Documentation

◆ ARRAY_BEGIN

const char anch::json::ARRAY_BEGIN = '['

JSON start array ('[')

◆ ARRAY_END

const char anch::json::ARRAY_END =']'

JSON start array (']')

◆ DEFAULT_MAPPING_OPTIONS

MappingOptions anch::json::DEFAULT_MAPPING_OPTIONS
extern

Default mapping options. It is not a constant so it can be changed in your application initialization.

◆ EMPTY_FIELD

const std::optional<std::string> anch::json::EMPTY_FIELD
extern

No field name constant value

◆ FIELD_SEPARATOR

const char anch::json::FIELD_SEPARATOR = ','

JSON fields delimiter (',')

◆ FIELD_VALUE_SEPARATOR

const char anch::json::FIELD_VALUE_SEPARATOR = ':'

JSON fiel/value delimiter (':')

◆ OBJECT_BEGIN

const char anch::json::OBJECT_BEGIN = '{'

JSON start object ('{')

◆ OBJECT_END

const char anch::json::OBJECT_END = '}'

JSON end object ('}')

◆ STRING_DELIMITER

const char anch::json::STRING_DELIMITER = '"'

JSON caracters string delimiter ('"')