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