JSON Voorhees
Killer JSON for C++
Serialization

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

Classes

struct  jsonv::version
 Represents a version used to extract and encode JSON objects from C++ classes. 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::extractor
 An extractor holds the method for converting a value 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::extractor_construction< T >
 
class  jsonv::extractor_for< T >
 
class  jsonv::function_extractor< T, FExtract >
 
class  jsonv::serializer_for< T >
 
class  jsonv::function_serializer< T, FToJson >
 
class  jsonv::adapter_for< T >
 
class  jsonv::function_adapter< T, FExtract, FToJson >
 
class  jsonv::optional_adapter< TOptional >
 An adapter for optional-like types. More...
 
class  jsonv::container_adapter< TContainer >
 An adapter for container types. More...
 
class  jsonv::wrapper_adapter< TWrapper >
 An adapter for "wrapper" types. More...
 
class  jsonv::enum_adapter< TEnum, FEnumComp, FValueComp >
 An adapter for enumeration types. More...
 
class  jsonv::polymorphic_adapter< TPointer >
 An adapter which can create polymorphic types. More...
 

Typedefs

using jsonv::demangle_function = std::function< std::string(string_view source)>
 Type of function used in setting a custom demangler. More...
 
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. More...
 

Enumerations

enum  jsonv::duplicate_type_action : unsigned char { jsonv::duplicate_type_action::ignore, jsonv::duplicate_type_action::replace, jsonv::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  jsonv::keyed_subtype_action : unsigned char { jsonv::keyed_subtype_action::none, jsonv::keyed_subtype_action::check, jsonv::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. More...
 
JSONV_PUBLIC void jsonv::set_demangle_function (demangle_function func)
 Sets the global demangle function. More...
 
JSONV_PUBLIC void jsonv::reset_demangle_function ()
 Resets the demangle function to the default. More...
 
JSONV_PUBLIC std::string jsonv::current_exception_type_name ()
 Get the demangled type name of the current exception. More...
 
template<typename T >
jsonv::extract (const value &from, const formats &fmts)
 Extract a C++ value from from using the provided fmts. More...
 
template<typename T >
jsonv::extract (const value &from)
 Extract a C++ value from from using jsonv::formats::global(). More...
 
template<typename T >
value jsonv::to_json (const T &from, const formats &fmts)
 Encode a JSON value from from using the provided fmts. More...
 
template<typename T >
value jsonv::to_json (const T &from)
 Encode a JSON value from from using jsonv::formats::global(). More...
 
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, FToJson > jsonv::make_serializer (FToJson to_json_)
 
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 >
 

Detailed Description

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

Typedef Documentation

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.

template<typename TEnum , typename FEnumComp = std::less<TEnum>>
using jsonv::enum_adapter_icase = typedef enum_adapter<TEnum, FEnumComp, value_less_icase>

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

See also
enum_adapter

Definition at line 519 of file serialization_util.hpp.

Enumeration Type Documentation

enum jsonv::duplicate_type_action : unsigned char
strong

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 116 of file serialization.hpp.

enum jsonv::keyed_subtype_action : unsigned char
strong

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 525 of file serialization_util.hpp.

Function Documentation

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.
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
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 622 of file serialization.hpp.

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

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

Definition at line 630 of file serialization.hpp.

JSONV_PUBLIC void jsonv::reset_demangle_function ( )

Resets the demangle function to the default.

See also
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
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 670 of file serialization.hpp.

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

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

Definition at line 678 of file serialization.hpp.