5#include <userver/formats/json/value.hpp>
6#include <userver/formats/parse/common_containers.hpp>
7#include <userver/formats/parse/to.hpp>
8#include <userver/utils/meta.hpp>
10#include <userver/chaotic/validators.hpp>
12USERVER_NAMESPACE_BEGIN
16template <
typename ItemType,
typename UserType,
typename... Validators>
18 const UserType& value;
21template <
typename Value,
typename ItemType,
typename UserType,
typename... Validators>
22UserType Parse(
const Value& value, formats::
parse::
To<Array<ItemType, UserType, Validators...>>) {
24 auto inserter = std::inserter(arr, arr.end());
25 if constexpr (meta::kIsReservable<UserType>) {
26 arr.reserve(value.GetSize());
28 for (
const auto& item : value) {
29 *inserter = item.
template As<ItemType>();
33 chaotic::Validate<Validators...>(arr, value);
38template <
typename Value,
typename ItemType,
typename... Validators>
39std::vector<formats::common::ParseType<Value, ItemType>>
40Parse(
const Value& value, formats::parse::To<Array<ItemType, std::vector<formats::common::ParseType<Value, ItemType>>, Validators...>>) {
41 std::vector<formats::common::ParseType<Value, ItemType>> arr;
42 arr.reserve(value.GetSize());
43 for (
const auto& item : value) {
44 arr.emplace_back(item.
template As<ItemType>());
47 chaotic::Validate<Validators...>(arr, value);
52template <
typename Value,
typename ItemType,
typename UserType,
typename... Validators>
53Value Serialize(
const Array<ItemType, UserType, Validators...>& ps, formats::
serialize::
To<Value>) {
55 for (
const auto& item : ps.value) {
56 vb.PushBack(ItemType{item});
58 return vb.ExtractValue();