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,
21 formats::
parse::
To<WithType<RawType, UserType>>) {
22 auto result = value.
template As<RawType>();
24 return Convert(result, convert::
To<UserType>{});
25 }
catch (
const std::exception& e) {
26 chaotic::ThrowForValue(e.what(), value);
30template <
typename Value,
typename RawType,
typename UserType>
31Value Serialize(
const WithType<RawType, UserType>& ps,
33 return typename Value::Builder{
34 RawType{Convert(ps.value,
35 convert::To<std::decay_t<
decltype(RawType::value)>>())}}