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>
|
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...
|
|
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 |
◆ build_json()
template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
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*>()))>
Convert object from nlohmann::json.
- Parameters
-
- 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{}))>
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