| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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...

`#include <json_interface.h>`

Inheritance diagram for dpp::json_interface< T >:
[legend]

## Public Member Functions

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.
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.
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.

## 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

  T | Type 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_id | Whether 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

  j | nlohmann::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_id | Whether 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.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0