D++ (DPP)
C++ Discord API Bot Library
dpp::json_interface< T > Struct Template Reference

Represents an interface for an object that can optionally implement functions for converting to and from nlohmann::json. The methods are only present if the actual object also has those methods. More...

+ Inheritance diagram for dpp::json_interface< T >:

Public Member Functions

template<typename U = T, typename = decltype(std::declval<U&>().fill_from_json_impl(std::declval<nlohmann::json*>()))>
T & fill_from_json (nlohmann::json *j)
 Convert object from nlohmann::json. More...
 
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
auto to_json (bool with_id=false) const
 Convert object to nlohmann::json. More...
 
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
std::string build_json (bool with_id=false) const
 Convert object to json string. More...
 

Detailed Description

template<typename T>
struct dpp::json_interface< T >

Represents an interface for an object that can optionally implement functions for converting to and from nlohmann::json. The methods are only present if the actual object also has those methods.

Template Parameters
TType of class that implements the interface

Member Function Documentation

◆ build_json()

template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
std::string dpp::json_interface< T >::build_json ( bool  with_id = false) const
inline

Convert object to json string.

Parameters
with_idWhether to include the ID or not
Note
Some fields are conditionally filled, do not rely on all fields being present
Returns
std::string Json built from the structure

◆ fill_from_json()

template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().fill_from_json_impl(std::declval<nlohmann::json*>()))>
T& dpp::json_interface< T >::fill_from_json ( nlohmann::json *  j)
inline

Convert object from nlohmann::json.

Parameters
jnlohmann::json object
Returns
T& Reference to self for fluent calling

◆ to_json()

template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
auto dpp::json_interface< T >::to_json ( bool  with_id = false) const
inline

Convert object to nlohmann::json.

Parameters
with_idWhether to include the ID or not
Note
Some fields are conditionally filled, do not rely on all fields being present
Returns
json Json built from the structure
D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0