2018-01-10 09:18:31 +00:00
|
|
|
#pragma once
|
2017-08-14 16:22:49 +00:00
|
|
|
|
2021-01-08 23:08:27 +00:00
|
|
|
#include <type_traits>
|
2017-08-14 16:22:49 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2018-01-29 10:21:11 +00:00
|
|
|
#include <nlohmann/detail/conversions/from_json.hpp>
|
|
|
|
#include <nlohmann/detail/conversions/to_json.hpp>
|
2021-01-10 18:23:32 +00:00
|
|
|
#include <nlohmann/detail/meta/identity_tag.hpp>
|
2021-01-08 23:08:27 +00:00
|
|
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
2017-08-14 16:22:49 +00:00
|
|
|
|
|
|
|
namespace nlohmann
|
|
|
|
{
|
2018-10-28 08:15:41 +00:00
|
|
|
|
2021-12-29 12:41:01 +00:00
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/
|
2021-01-08 23:08:27 +00:00
|
|
|
template<typename ValueType, typename>
|
2017-08-14 16:22:49 +00:00
|
|
|
struct adl_serializer
|
|
|
|
{
|
2021-12-29 12:41:01 +00:00
|
|
|
/// @brief convert a JSON value to any value type
|
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
|
2021-01-09 16:45:56 +00:00
|
|
|
template<typename BasicJsonType, typename TargetType = ValueType>
|
|
|
|
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
|
2018-10-28 08:15:41 +00:00
|
|
|
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
|
|
|
|
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
|
2017-08-14 16:22:49 +00:00
|
|
|
{
|
|
|
|
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
|
|
|
|
}
|
|
|
|
|
2021-12-29 12:41:01 +00:00
|
|
|
/// @brief convert a JSON value to any value type
|
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
|
2021-01-09 16:45:56 +00:00
|
|
|
template<typename BasicJsonType, typename TargetType = ValueType>
|
2021-01-08 23:08:27 +00:00
|
|
|
static auto from_json(BasicJsonType && j) noexcept(
|
2021-01-10 18:23:32 +00:00
|
|
|
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
|
|
|
|
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
|
2021-01-08 23:08:27 +00:00
|
|
|
{
|
2021-01-10 18:23:32 +00:00
|
|
|
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
|
2021-01-08 23:08:27 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 12:41:01 +00:00
|
|
|
/// @brief convert any value type to a JSON value
|
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
|
2021-01-09 16:45:56 +00:00
|
|
|
template<typename BasicJsonType, typename TargetType = ValueType>
|
|
|
|
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
|
|
|
|
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
|
|
|
|
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
|
2017-08-14 16:22:49 +00:00
|
|
|
{
|
2021-01-09 16:45:56 +00:00
|
|
|
::nlohmann::to_json(j, std::forward<TargetType>(val));
|
2017-08-14 16:22:49 +00:00
|
|
|
}
|
|
|
|
};
|
2018-10-07 16:39:18 +00:00
|
|
|
} // namespace nlohmann
|