|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <utility> |
| 4 | + |
| 5 | +#include <nlohmann/detail/conversions/from_json.hpp> |
| 6 | +#include <nlohmann/detail/conversions/to_json.hpp> |
| 7 | + |
| 8 | +namespace nlohmann |
| 9 | +{ |
| 10 | +template<typename, typename> |
| 11 | +struct adl_serializer |
| 12 | +{ |
| 13 | + /*! |
| 14 | + @brief convert a JSON value to any value type |
| 15 | +
|
| 16 | + This function is usually called by the `get()` function of the |
| 17 | + @ref basic_json class (either explicit or via conversion operators). |
| 18 | +
|
| 19 | + @param[in] j JSON value to read from |
| 20 | + @param[in,out] val value to write to |
| 21 | + */ |
| 22 | + template<typename BasicJsonType, typename ValueType> |
| 23 | + static auto from_json(BasicJsonType&& j, ValueType& val) noexcept( |
| 24 | + noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val))) -> decltype( |
| 25 | + ::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void() |
| 26 | + ) |
| 27 | + { |
| 28 | + ::nlohmann::from_json(std::forward<BasicJsonType>(j), val); |
| 29 | + } |
| 30 | + |
| 31 | + /*! |
| 32 | + @brief convert any value type to a JSON value |
| 33 | +
|
| 34 | + This function is usually called by the constructors of the @ref basic_json |
| 35 | + class. |
| 36 | +
|
| 37 | + @param[in,out] j JSON value to write to |
| 38 | + @param[in] val value to read from |
| 39 | + */ |
| 40 | + template <typename BasicJsonType, typename ValueType> |
| 41 | + static auto to_json(BasicJsonType& j, ValueType&& val) noexcept( |
| 42 | + noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val)))) |
| 43 | + -> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), |
| 44 | + void()) |
| 45 | + { |
| 46 | + ::nlohmann::to_json(j, std::forward<ValueType>(val)); |
| 47 | + } |
| 48 | +}; |
| 49 | +} |
0 commit comments