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

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.

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.

Friends

template<typename U>
struct SerializationTraits

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 54 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 102 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

Member Function Documentation

◆ 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

◆ options()

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

Get current serialization options.

Returns
Current options

◆ setOptions()

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

Set serialization options.

Parameters
optionsNew options to use

◆ 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

◆ SerializationTraits

template<typename T>
template<typename U>
friend struct SerializationTraits
friend

Definition at line 57 of file Serializer.h.


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