JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
Serialization

Serialization components are responsible for conversion between a C++ type and a JSON value. More...

Classes

class  jsonv::reader
 A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON ast_node sequence. More...
 
class  jsonv::duplicate_type_error
 Exception thrown if an insertion of an extractor or serializer into a formats is attempted, but there is already an extractor or serializer for that type. More...
 
class  jsonv::extraction_error
 Exception thrown if there is any problem running extract. More...
 
class  jsonv::no_extractor
 Thrown when formats::extract does not have an extractor for the provided type. More...
 
class  jsonv::no_serializer
 Thrown when formats::to_json does not have a serializer for the provided type. More...
 
class  jsonv::extract_options
 Configuration for various extraction options. This becomes part of the extraction_context. More...
 
class  jsonv::extractor
 An extractor holds the method for converting JSON source into an arbitrary C++ type. More...
 
class  jsonv::serializer
 A serializer holds the method for converting an arbitrary C++ type into a value. More...
 
class  jsonv::adapter
 An adapter is both an extractor and a serializer. More...
 
class  jsonv::formats
 Simply put, this class is a collection of extractor and serializer instances. More...
 
class  jsonv::context_base
 Provides extra information to routines used for extraction. More...
 
class  jsonv::extraction_context
 
class  jsonv::serialization_context
 
class  jsonv::adapter_for< T >
 An adapter for the type T. More...
 
class  jsonv::container_adapter< TContainer >
 An adapter for container types. More...
 
class  jsonv::enum_adapter< TEnum, FEnumComp, FValueComp >
 An adapter for enumeration types. More...
 
class  jsonv::extractor_construction< T >
 An extractor for type T that has a constructor that accepts either a jsonv::value or a jsonv::value and extraction_context. More...
 
class  jsonv::extractor_for< T >
 An extractor for the type T. More...
 
class  jsonv::function_adapter< T, FExtract, FToJson >
 
class  jsonv::function_extractor< T, FExtract >
 An extractor which calls a function to perform extraction. More...
 
class  jsonv::function_serializer< T, FToJson >
 
class  jsonv::optional_adapter< TOptional >
 An adapter for optional-like types. More...
 
class  jsonv::polymorphic_adapter< TPointer >
 An adapter which can create polymorphic types. More...
 
class  jsonv::serializer_for< T >
 
class  jsonv::wrapper_adapter< TWrapper >
 An adapter for "wrapper" types. More...
 

Typedefs

using jsonv::demangle_function = std::function< std::string(string_view source)>
 Type of function used in setting a custom demangler.
 
template<typename TEnum , typename FEnumComp = std::less<TEnum>>
using jsonv::enum_adapter_icase = enum_adapter< TEnum, FEnumComp, value_less_icase >
 An adapter for enumeration types which ignores the case when extracting from JSON.
 

Enumerations

enum class  jsonv::duplicate_type_action : unsigned char { duplicate_type_action::ignore , duplicate_type_action::replace , duplicate_type_action::exception }
 The action to take when an insertion of an extractor or serializer into a formats is attempted, but there is alredy an extractor or serializer for that type. More...
 
enum class  jsonv::keyed_subtype_action : unsigned char { keyed_subtype_action::none , keyed_subtype_action::check , keyed_subtype_action::insert }
 What to do when serializing a keyed subtype of a polymorphic_adapter. More...
 

Functions

JSONV_PUBLIC std::string jsonv::demangle (string_view source)
 Convert the input source from a mangled type into a human-friendly version.
 
JSONV_PUBLIC void jsonv::set_demangle_function (demangle_function func)
 Sets the global demangle function.
 
JSONV_PUBLIC void jsonv::reset_demangle_function ()
 Resets the demangle function to the default.
 
JSONV_PUBLIC std::string jsonv::current_exception_type_name ()
 Get the demangled type name of the current exception.
 
template<typename T >
jsonv::extract (const value &from, const formats &fmts)
 Extract a C++ value from from using the provided fmts.
 
template<typename T >
jsonv::extract (const value &from)
 Extract a C++ value from from using jsonv::formats::global().
 
template<typename T >
value jsonv::to_json (const T &from, const formats &fmts)
 Encode a JSON value from from using the provided fmts.
 
template<typename T >
value jsonv::to_json (const T &from)
 Encode a JSON value from from using jsonv::formats::global().
 
template<typename FExtract , typename FToJson >
auto jsonv::make_adapter (FExtract extract, FToJson to_json_) -> function_adapter< decltype(extract(std::declval< const extraction_context & >(), std::declval< const value & >())), FExtract, FToJson >
 
template<typename FExtract , typename FToJson , typename = void>
auto jsonv::make_adapter (FExtract extract, FToJson to_json_) -> function_adapter< decltype(extract(std::declval< const value & >())), FExtract, FToJson >
 
template<typename FExtract >
auto jsonv::make_extractor (FExtract func) -> function_extractor< decltype(func(std::declval< const extraction_context & >(), std::declval< const value & >())), FExtract >
 
template<typename FExtract , typename = void>
auto jsonv::make_extractor (FExtract func) -> function_extractor< decltype(func(std::declval< const value & >())), FExtract >
 
template<typename T , typename FToJson >
function_serializer< T, FToJsonjsonv::make_serializer (FToJson to_json_)
 

Detailed Description

Serialization components are responsible for conversion between a C++ type and a JSON value.

Typedef Documentation

◆ demangle_function

using jsonv::demangle_function = typedef std::function<std::string (string_view source)>

Type of function used in setting a custom demangler.

See also
demangle
set_demangle_function

Definition at line 40 of file demangle.hpp.

◆ enum_adapter_icase

An adapter for enumeration types which ignores the case when extracting from JSON.

See also
enum_adapter

Definition at line 118 of file enum_adapter.hpp.

Enumeration Type Documentation

◆ duplicate_type_action

The action to take when an insertion of an extractor or serializer into a formats is attempted, but there is alredy an extractor or serializer for that type.

Enumerator
ignore 

The existing extractor or serializer should be kept, but no exception should be thrown.

replace 

The new extractor or serializer should be inserted, and no exception should be thrown.

exception 

A duplicate_type_error should be thrown.

Definition at line 42 of file serialization.hpp.

◆ keyed_subtype_action

What to do when serializing a keyed subtype of a polymorphic_adapter.

See polymorphic_adapter::add_subtype_keyed.

Enumerator
none 

Don't do any checking or insertion of the expected key/value pair.

check 

Ensure the correct key/value pair was inserted by serialization. Throws std::runtime_error if it wasn't.

insert 

Insert the correct key/value pair as part of serialization.

Throws std::runtime_error if the key is already present.

Definition at line 23 of file polymorphic_adapter.hpp.

Function Documentation

◆ current_exception_type_name()

JSONV_PUBLIC std::string jsonv::current_exception_type_name ( )

Get the demangled type name of the current exception.

This is meant to be called from catch (...) blocks to attempt to get more information about the exception type when it doesn't derive from a known entity.

Returns
The demangled type name of the current exception or "unknown" if this cannot be discovered. Failure to discover is not an error – this can happen if the exception is foreign to C++ (it does not have a std::type_info implementation) or if discovery is not known for this platform.

◆ demangle()

JSONV_PUBLIC std::string jsonv::demangle ( string_view  source)

Convert the input source from a mangled type into a human-friendly version.

This is used by formats (and the associated serialization functions) to give more user-friendly names in type errors.

See also
demangle_function
set_demangle_function

◆ extract() [1/2]

template<typename T >
T jsonv::extract ( const value from)

Extract a C++ value from from using jsonv::formats::global().

Definition at line 689 of file serialization.hpp.

+ Here is the call graph for this function:

◆ extract() [2/2]

template<typename T >
T jsonv::extract ( const value from,
const formats fmts 
)

Extract a C++ value from from using the provided fmts.

Definition at line 681 of file serialization.hpp.

+ Here is the call graph for this function:

◆ make_adapter() [1/2]

auto jsonv::make_adapter ( FExtract  extract,
FToJson  to_json_ 
) -> function_adapter<decltype(extract(std::declval<const extraction_context&>(), std::declval<const value&>())), FExtract, FToJson >

Definition at line 80 of file function_adapter.hpp.

◆ make_adapter() [2/2]

template<typename FExtract , typename FToJson , typename = void>
auto jsonv::make_adapter ( FExtract  extract,
FToJson  to_json_ 
) -> function_adapter<decltype(extract(std::declval<const value&>())), FExtract, FToJson >

Definition at line 94 of file function_adapter.hpp.

◆ make_extractor() [1/2]

template<typename FExtract >
auto jsonv::make_extractor ( FExtract  func) -> function_extractor<decltype(func(std::declval<const extraction_context&>(), std::declval<const value&>())), FExtract >

Definition at line 60 of file function_extractor.hpp.

◆ make_extractor() [2/2]

template<typename FExtract , typename = void>
auto jsonv::make_extractor ( FExtract  func) -> function_extractor<decltype(func(std::declval<const value&>())), FExtract >

Definition at line 72 of file function_extractor.hpp.

◆ make_serializer()

template<typename T , typename FToJson >
function_serializer< T, FToJson > jsonv::make_serializer ( FToJson  to_json_)

Definition at line 60 of file function_serializer.hpp.

◆ reset_demangle_function()

JSONV_PUBLIC void jsonv::reset_demangle_function ( )

Resets the demangle function to the default.

See also
set_demangle_function

◆ set_demangle_function()

JSONV_PUBLIC void jsonv::set_demangle_function ( demangle_function  func)

Sets the global demangle function.

This controls the behavior of demangle – the provided func will be called by demangle.

See also
demangle

◆ to_json() [1/2]

template<typename T >
value jsonv::to_json ( const T &  from)

Encode a JSON value from from using jsonv::formats::global().

Definition at line 735 of file serialization.hpp.

+ Here is the call graph for this function:

◆ to_json() [2/2]

template<typename T >
value jsonv::to_json ( const T &  from,
const formats fmts 
)

Encode a JSON value from from using the provided fmts.

Definition at line 727 of file serialization.hpp.

+ Here is the call graph for this function: