userver: userver/formats/json/serialize_boost_variant.hpp Source File
Loading...
Searching...
No Matches
serialize_boost_variant.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/json/serialize_boost_variant.hpp
4/// @brief Serializers for boost::variant types.
5/// @ingroup userver_universal userver_formats_serialize
6
7#include <boost/variant/apply_visitor.hpp>
8#include <boost/variant/variant.hpp>
9
10#include <userver/formats/json/value_builder.hpp>
11#include <userver/formats/serialize/to.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15/// @brief Generic serialization helpers (`formats::serialize::To` and friends).
16namespace formats::serialize {
17
18template <typename... Types>
19formats::json::Value Serialize(const boost::variant<Types...>& value, To<formats::json::Value>) {
20 return boost::apply_visitor(
21 [](const auto& item) { return formats::json::ValueBuilder(item).ExtractValue(); },
22 value
23 );
24}
25
26} // namespace formats::serialize
27
28USERVER_NAMESPACE_END