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,
22 typename... Validators>
23UserType Parse(
const Value& value,
24 formats::
parse::
To<Array<ItemType, UserType, Validators...>>) {
26 auto inserter = std::inserter(arr, arr.end());
27 if constexpr (meta::kIsReservable<UserType>) {
28 arr.reserve(value.GetSize());
30 for (
const auto& item : value) {
31 *inserter = item.
template As<ItemType>();
35 chaotic::Validate<Validators...>(arr, value);
40template <
typename Value,
typename ItemType,
typename... Validators>
41std::vector<formats::common::ParseType<Value, ItemType>> Parse(
43 formats::parse::To<Array<
44 ItemType, std::vector<formats::common::ParseType<Value, ItemType>>,
46 std::vector<formats::common::ParseType<Value, ItemType>> arr;
47 arr.reserve(value.GetSize());
48 for (
const auto& item : value) {
49 arr.emplace_back(item.
template As<ItemType>());
52 chaotic::Validate<Validators...>(arr, value);
57template <
typename Value,
typename ItemType,
typename UserType,
58 typename... Validators>
59Value Serialize(
const Array<ItemType, UserType, Validators...>& ps,
62 for (
const auto& item : ps.value) {
63 vb.PushBack(ItemType{item});
65 return vb.ExtractValue();