49#if __has_include( "nfx/datatypes/Int128.h" )
51# include "nfx/datatypes/Int128.h"
53namespace nfx::serialization::json
69 static void serialize(
const nfx::datatypes::Int128& obj, Document& doc )
71 std::string value = obj.toString();
72 doc.set<std::string>(
"", value );
82 static void deserialize( nfx::datatypes::Int128& obj,
const Document& doc )
84 if ( doc.is<std::string>(
"" ) )
86 auto val = doc.get<std::string>(
"" );
87 if ( val.has_value() && !val.value().empty() )
89 if ( !nfx::datatypes::Int128::fromString( val.value(), obj ) )
91 throw std::runtime_error(
"Invalid Int128 format: unable to parse string representation" );
105#if __has_include( "nfx/datatypes/Decimal.h" )
107# include "nfx/datatypes/Decimal.h"
109namespace nfx::serialization::json
124 static void serialize(
const nfx::datatypes::Decimal& obj, Document& doc )
126 std::string value = obj.toString();
127 doc.set<std::string>(
"", value );
137 static void deserialize( nfx::datatypes::Decimal& obj,
const Document& doc )
139 if ( doc.is<std::string>(
"" ) )
141 auto val = doc.get<std::string>(
"" );
142 if ( val.has_value() && !val.value().empty() )
144 if ( !nfx::datatypes::Decimal::fromString( val.value(), obj ) )
146 throw std::runtime_error(
"Invalid Decimal format: unable to parse string representation" );
Generic document abstraction for JSON serialization.
Serialization traits and type specializations for JSON serialization.
Default serialization traits - users can specialize this.
static void serialize(const T &obj, Document &doc)
Default serialize implementation - delegates to member method.
static void deserialize(T &obj, const Document &doc)
Default deserialize implementation - delegates to member method.