nfx-serialization 0.3.0
Cross-platform C++ JSON serialization library with extensible trait capabilities
Loading...
Searching...
No Matches
nfx::serialization::json::Serializer< T > Class Template Reference

Templated JSON serializer with compile-time type mapping. More...

#include <nfx/serialization/json/Serializer.h>

Classes

struct  Options
 Serialization options and context. More...

Public Types

using value_type = T
 The type being serialized/deserialized.

Public Member Functions

 Serializer ()=default
 Default constructor.
 Serializer (const Options &options) noexcept
 Constructor with options.
const Optionsoptions () const noexcept
 Get current serialization options.
void setOptions (const Options &options) noexcept
 Set serialization options.
Document serialize (const T &obj) const
 Serialize object to JSON document.
deserialize (const Document &doc) const
 Deserialize object from JSON document.

Static Public Member Functions

static std::string toString (const T &obj, const Options &options={})
 Serialize object to JSON string.
static T fromString (std::string_view jsonStr, const Options &options={})
 Deserialize object from JSON string.

Detailed Description

template<typename T>
class nfx::serialization::json::Serializer< T >

Templated JSON serializer with compile-time type mapping.

Template Parameters
TThe type to serialize/deserialize

Provides automatic serialization and deserialization of C++ objects to/from JSON using compile-time type detection and traits.

Definition at line 51 of file Serializer.h.

Member Typedef Documentation

◆ value_type

template<typename T>
using nfx::serialization::json::Serializer< T >::value_type = T

The type being serialized/deserialized.

Definition at line 95 of file Serializer.h.

Constructor & Destructor Documentation

◆ Serializer()

template<typename T>
nfx::serialization::json::Serializer< T >::Serializer ( const Options & options)
inlineexplicitnoexcept

Constructor with options.

Parameters
optionsSerialization options to use
Here is the call graph for this function:

Member Function Documentation

◆ deserialize()

template<typename T>
T nfx::serialization::json::Serializer< T >::deserialize ( const Document & doc) const
inline

Deserialize object from JSON document.

Parameters
docThe document to deserialize from
Returns
Deserialized object
Exceptions
std::runtime_errorif deserialization fails
Here is the caller graph for this function:

◆ fromString()

template<typename T>
T nfx::serialization::json::Serializer< T >::fromString ( std::string_view jsonStr,
const Options & options = {} )
inlinestatic

Deserialize object from JSON string.

Template Parameters
TType of object to deserialize
Parameters
jsonStrJSON string to deserialize from
optionsSerialization options (optional, uses defaults if not provided)
Returns
Deserialized object
Here is the call graph for this function:

◆ options()

template<typename T>
const Options & nfx::serialization::json::Serializer< T >::options ( ) const
inlinenoexcept

Get current serialization options.

Returns
Current options
Here is the caller graph for this function:

◆ serialize()

template<typename T>
Document nfx::serialization::json::Serializer< T >::serialize ( const T & obj) const
inline

Serialize object to JSON document.

Parameters
objThe object to serialize
Returns
Document containing the serialized JSON
Exceptions
std::runtime_errorif serialization fails
Here is the caller graph for this function:

◆ setOptions()

template<typename T>
void nfx::serialization::json::Serializer< T >::setOptions ( const Options & options)
inlinenoexcept

Set serialization options.

Parameters
optionsNew options to use
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

template<typename T>
std::string nfx::serialization::json::Serializer< T >::toString ( const T & obj,
const Options & options = {} )
inlinestatic

Serialize object to JSON string.

Template Parameters
TType of object to serialize
Parameters
objObject to serialize
optionsSerialization options (optional, uses defaults if not provided)
Returns
JSON string representation
Here is the call graph for this function:
Here is the caller graph for this function:

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