5#include <userver/formats/json/value.hpp>
6#include <userver/formats/parse/to.hpp>
7#include <userver/formats/serialize/to.hpp>
8#include <userver/utils/meta.hpp>
9#include <userver/utils/overloaded.hpp>
11USERVER_NAMESPACE_BEGIN
15template <
typename... T>
16auto& GetVariant(std::variant<T...>& arg) {
20template <
typename... T>
21const auto& GetVariant(
const std::variant<T...>& arg) {
26decltype(T().AsVariant()) GetVariant(T& arg) {
27 return arg.AsVariant();
30template <
typename... T>
32 const std::variant<
decltype(Parse(std::declval<formats::json::Value>(),
33 formats::parse::To<T>{}))...>& value;
36template <
typename Value,
typename... T>
37auto Parse(
const Value& value, formats::
parse::
To<Variant<T...>>) {
38 return value.
template As<std::variant<T...>>();
41template <
typename Value,
typename... T>
42Value Serialize(
const Variant<T...>& var, formats::
serialize::
To<Value>) {
44 utils::Overloaded{[](
const formats::common::ParseType<Value, T>& item) {
45 return typename Value::Builder(T{item}).ExtractValue();