C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
essence::meta::runtime::json_serializer< T, typename > Struct Template Reference

A JSON serializer by using the meta reflection implementation in this project. More...

#include <json_serializer.hpp>

Static Public Member Functions

template<typename U , typename BasicJsonContext >
requires nlohmann::detail::is_basic_json_context<BasicJsonContext>::value
static void throw_exception (const U &member, std::string_view json_key, std::string_view message, std::string_view internal, BasicJsonContext context)
 
template<typename BasicJson , typename U = T>
requires ( nlohmann::detail::is_basic_json<BasicJson>::value && (nlohmann::detail::is_compatible_type<nlohmann::json, U>::value || std::ranges::forward_range<U>) && !std::is_enum_v<U>)
static void to_json (BasicJson &json, const U &value)
 Serializes a primitive value to a JSON value.
 
template<typename BasicJson , typename U = T>
requires ( nlohmann::detail::is_basic_json<BasicJson>::value && (nlohmann::detail::is_compatible_type<nlohmann::json, U>::value || std::ranges::forward_range<U>) && !std::is_enum_v<U>)
static void from_json (const BasicJson &json, U &value)
 Deserializes a JSON value to a primitive value.
 
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std_optional<U>)
static void to_json (BasicJson &json, const U &value)
 Serializes a std::optional<> value to a JSON value.
 
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std_optional<U>)
static void from_json (const BasicJson &json, U &value)
 Deserializes a JSON value to a std::optional<> value.
 
template<typename BasicJson , typename U = T>
requires (std::is_class_v<U> && nlohmann::detail::is_basic_json<BasicJson>::value && !nlohmann::detail::is_compatible_type<nlohmann::json, U>::value && !std::ranges::forward_range<U> && !std_optional<U>)
static void to_json (BasicJson &json, const U &value)
 Serializes a non-iterable class object to a JSON value.
 
template<typename BasicJson , typename U = T>
requires (std::is_class_v<U> && nlohmann::detail::is_basic_json<BasicJson>::value && !nlohmann::detail::is_compatible_type<nlohmann::json, U>::value && !std::ranges::forward_range<U> && !std_optional<U>)
static void from_json (const BasicJson &json, U &value)
 Deserializes a JSON value to a non-iterable class object.
 
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std::same_as<typename BasicJson::string_t::value_type, char> && std::is_enum_v<U>)
static void to_json (BasicJson &json, const U &value)
 Serializes an enumeration value to a JSON value.
 
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std::same_as<typename BasicJson::string_t::value_type, char> && std::is_enum_v<U>)
static void from_json (const BasicJson &json, U &value)
 Deserializes a JSON value to an enumeration value.
 

Detailed Description

template<typename T, typename = void>
struct essence::meta::runtime::json_serializer< T, typename >

A JSON serializer by using the meta reflection implementation in this project.

Template Parameters
TThe type of the value.

Member Function Documentation

◆ from_json() [1/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires ( nlohmann::detail::is_basic_json<BasicJson>::value && (nlohmann::detail::is_compatible_type<nlohmann::json, U>::value || std::ranges::forward_range<U>) && !std::is_enum_v<U>)
static void essence::meta::runtime::json_serializer< T, typename >::from_json ( const BasicJson & json,
U & value )
inlinestatic

Deserializes a JSON value to a primitive value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe primitive value.

◆ from_json() [2/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std_optional<U>)
static void essence::meta::runtime::json_serializer< T, typename >::from_json ( const BasicJson & json,
U & value )
inlinestatic

Deserializes a JSON value to a std::optional<> value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe std::optional<> value.

◆ from_json() [3/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires (std::is_class_v<U> && nlohmann::detail::is_basic_json<BasicJson>::value && !nlohmann::detail::is_compatible_type<nlohmann::json, U>::value && !std::ranges::forward_range<U> && !std_optional<U>)
static void essence::meta::runtime::json_serializer< T, typename >::from_json ( const BasicJson & json,
U & value )
inlinestatic

Deserializes a JSON value to a non-iterable class object.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe class object.

◆ from_json() [4/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std::same_as<typename BasicJson::string_t::value_type, char> && std::is_enum_v<U>)
static void essence::meta::runtime::json_serializer< T, typename >::from_json ( const BasicJson & json,
U & value )
inlinestatic

Deserializes a JSON value to an enumeration value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe enumeration value.

◆ to_json() [1/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires ( nlohmann::detail::is_basic_json<BasicJson>::value && (nlohmann::detail::is_compatible_type<nlohmann::json, U>::value || std::ranges::forward_range<U>) && !std::is_enum_v<U>)
static void essence::meta::runtime::json_serializer< T, typename >::to_json ( BasicJson & json,
const U & value )
inlinestatic

Serializes a primitive value to a JSON value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe primitive value.

◆ to_json() [2/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std_optional<U>)
static void essence::meta::runtime::json_serializer< T, typename >::to_json ( BasicJson & json,
const U & value )
inlinestatic

Serializes a std::optional<> value to a JSON value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe std::optional<> value.

◆ to_json() [3/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires (std::is_class_v<U> && nlohmann::detail::is_basic_json<BasicJson>::value && !nlohmann::detail::is_compatible_type<nlohmann::json, U>::value && !std::ranges::forward_range<U> && !std_optional<U>)
static void essence::meta::runtime::json_serializer< T, typename >::to_json ( BasicJson & json,
const U & value )
inlinestatic

Serializes a non-iterable class object to a JSON value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe class object.

◆ to_json() [4/4]

template<typename T , typename = void>
template<typename BasicJson , typename U = T>
requires (nlohmann::detail::is_basic_json<BasicJson>::value && std::same_as<typename BasicJson::string_t::value_type, char> && std::is_enum_v<U>)
static void essence::meta::runtime::json_serializer< T, typename >::to_json ( BasicJson & json,
const U & value )
inlinestatic

Serializes an enumeration value to a JSON value.

Template Parameters
BasicJsonThe type of the JSON.
UA type placeholder to support overload resolution.
Parameters
jsonThe JSON value.
valueThe enumeration value.

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