3#include <userver/formats/json/value.hpp>
4#include <userver/formats/parse/to.hpp>
6#include <userver/chaotic/convert.hpp>
7#include <userver/chaotic/convert/to.hpp>
8#include <userver/chaotic/exception.hpp>
10USERVER_NAMESPACE_BEGIN
14template <
typename RawType,
typename UserType>
15struct WithType final {
16 const UserType& value;
19template <
typename Value,
typename RawType,
typename UserType>
20UserType Parse(
const Value& value, formats::
parse::
To<WithType<RawType, UserType>>) {
21 auto result = value.
template As<RawType>();
23 return Convert(result, convert::
To<UserType>{});
24 }
catch (
const std::exception& e) {
25 chaotic::ThrowForValue(e.what(), value);
29template <
typename Value,
typename RawType,
typename UserType>
30Value Serialize(
const WithType<RawType, UserType>& ps, formats::
serialize::
To<Value>) {
31 return typename Value::Builder{RawType{Convert(ps.value, convert::To<std::decay_t<
decltype(RawType::value)>>())}}