JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::serializer Class Referenceabstract

A serializer holds the method for converting an arbitrary C++ type into JSON, written token by token into a writer. More...

#include <jsonv/serialization/serializer.hpp>

+ Inheritance diagram for jsonv::serializer:

Public Member Functions

virtual const std::type_info & get_type () const noexcept=0
 Get the run-time type this serializer knows how to serialize.
 
virtual void serialize (const serialization_context &context, const void *from, writer &to) const =0
 Write the value in the given region of memory from into to.
 

Detailed Description

A serializer holds the method for converting an arbitrary C++ type into JSON, written token by token into a writer.

Definition at line 26 of file serializer.hpp.

Member Function Documentation

◆ get_type()

virtual const std::type_info & jsonv::serializer::get_type ( ) const
pure virtualnoexcept

Get the run-time type this serializer knows how to serialize.

Once this serializer is registered with a formats, it is not allowed to change.

Implemented in jsonv::adapter_for< T >, jsonv::adapter_for< TContainer >, jsonv::adapter_for< TEnum >, jsonv::adapter_for< TOptional >, jsonv::adapter_for< TPointer >, jsonv::adapter_for< TWrapper >, and jsonv::serializer_for< T >.

◆ serialize()

virtual void jsonv::serializer::serialize ( const serialization_context &  context,
const void *  from,
writer &  to 
) const
pure virtual

Write the value in the given region of memory from into to.

Parameters
contextExtra information to help you serialize sub-objects for your type, such as the ability to find other serializer implementations via formats. Serialize each part of your type through serialization_context::serialize: anything thrown while doing so comes out of it as a serialization_error naming the type and the position in the document, as writer::current_path reports it.
fromThe region of memory that represents the C++ value to convert to JSON. The pointer comes as the result of a static_cast<const void*>, so performing a static_cast back to your type is okay.
toThe writer to write into, positioned where the value goes: at the root, as the next element of an open array, or as the value of the key just written. Write exactly one value – a scalar, or a structure you open and close – and nothing else. To refuse, throw: to.current_path() is where you are.
See also
serializer_for
value_serializer_for
adapter_for

Implemented in jsonv::adapter_for< T >, jsonv::adapter_for< TContainer >, jsonv::adapter_for< TEnum >, jsonv::adapter_for< TOptional >, jsonv::adapter_for< TPointer >, jsonv::adapter_for< TWrapper >, and jsonv::serializer_for< T >.


The documentation for this class was generated from the following file: