1c5f01b2fSopenharmony_ci//     __ _____ _____ _____
2c5f01b2fSopenharmony_ci//  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
3c5f01b2fSopenharmony_ci// |  |  |__   |  |  | | | |  version 3.11.2
4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___|  https://github.com/nlohmann/json
5c5f01b2fSopenharmony_ci//
6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT
8c5f01b2fSopenharmony_ci
9c5f01b2fSopenharmony_ci#include <string>
10c5f01b2fSopenharmony_ci#include <vector>
11c5f01b2fSopenharmony_ci#include "doctest_compatibility.h"
12c5f01b2fSopenharmony_ci
13c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
14c5f01b2fSopenharmony_ciusing nlohmann::json;
15c5f01b2fSopenharmony_ci
16c5f01b2fSopenharmony_cinamespace persons
17c5f01b2fSopenharmony_ci{
18c5f01b2fSopenharmony_ciclass person_with_private_data
19c5f01b2fSopenharmony_ci{
20c5f01b2fSopenharmony_ci  private:
21c5f01b2fSopenharmony_ci    std::string name{};
22c5f01b2fSopenharmony_ci    int age = 0;
23c5f01b2fSopenharmony_ci    json metadata = nullptr;
24c5f01b2fSopenharmony_ci
25c5f01b2fSopenharmony_ci  public:
26c5f01b2fSopenharmony_ci    bool operator==(const person_with_private_data& rhs) const
27c5f01b2fSopenharmony_ci    {
28c5f01b2fSopenharmony_ci        return name == rhs.name && age == rhs.age && metadata == rhs.metadata;
29c5f01b2fSopenharmony_ci    }
30c5f01b2fSopenharmony_ci
31c5f01b2fSopenharmony_ci    person_with_private_data() = default;
32c5f01b2fSopenharmony_ci    person_with_private_data(std::string name_, int age_, json metadata_)
33c5f01b2fSopenharmony_ci        : name(std::move(name_))
34c5f01b2fSopenharmony_ci        , age(age_)
35c5f01b2fSopenharmony_ci        , metadata(std::move(metadata_))
36c5f01b2fSopenharmony_ci    {}
37c5f01b2fSopenharmony_ci
38c5f01b2fSopenharmony_ci    NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_data, age, name, metadata)
39c5f01b2fSopenharmony_ci};
40c5f01b2fSopenharmony_ci
41c5f01b2fSopenharmony_ciclass person_with_private_data_2
42c5f01b2fSopenharmony_ci{
43c5f01b2fSopenharmony_ci  private:
44c5f01b2fSopenharmony_ci    std::string name{};
45c5f01b2fSopenharmony_ci    int age = 0;
46c5f01b2fSopenharmony_ci    json metadata = nullptr;
47c5f01b2fSopenharmony_ci
48c5f01b2fSopenharmony_ci  public:
49c5f01b2fSopenharmony_ci    bool operator==(const person_with_private_data_2& rhs) const
50c5f01b2fSopenharmony_ci    {
51c5f01b2fSopenharmony_ci        return name == rhs.name && age == rhs.age && metadata == rhs.metadata;
52c5f01b2fSopenharmony_ci    }
53c5f01b2fSopenharmony_ci
54c5f01b2fSopenharmony_ci    person_with_private_data_2() = default;
55c5f01b2fSopenharmony_ci    person_with_private_data_2(std::string name_, int age_, json metadata_)
56c5f01b2fSopenharmony_ci        : name(std::move(name_))
57c5f01b2fSopenharmony_ci        , age(age_)
58c5f01b2fSopenharmony_ci        , metadata(std::move(metadata_))
59c5f01b2fSopenharmony_ci    {}
60c5f01b2fSopenharmony_ci
61c5f01b2fSopenharmony_ci    std::string getName() const
62c5f01b2fSopenharmony_ci    {
63c5f01b2fSopenharmony_ci        return name;
64c5f01b2fSopenharmony_ci    }
65c5f01b2fSopenharmony_ci    int getAge() const
66c5f01b2fSopenharmony_ci    {
67c5f01b2fSopenharmony_ci        return age;
68c5f01b2fSopenharmony_ci    }
69c5f01b2fSopenharmony_ci    json getMetadata() const
70c5f01b2fSopenharmony_ci    {
71c5f01b2fSopenharmony_ci        return metadata;
72c5f01b2fSopenharmony_ci    }
73c5f01b2fSopenharmony_ci
74c5f01b2fSopenharmony_ci    NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(person_with_private_data_2, age, name, metadata)
75c5f01b2fSopenharmony_ci};
76c5f01b2fSopenharmony_ci
77c5f01b2fSopenharmony_ciclass person_without_private_data_1
78c5f01b2fSopenharmony_ci{
79c5f01b2fSopenharmony_ci  public:
80c5f01b2fSopenharmony_ci    std::string name{};
81c5f01b2fSopenharmony_ci    int age = 0;
82c5f01b2fSopenharmony_ci    json metadata = nullptr;
83c5f01b2fSopenharmony_ci
84c5f01b2fSopenharmony_ci    bool operator==(const person_without_private_data_1& rhs) const
85c5f01b2fSopenharmony_ci    {
86c5f01b2fSopenharmony_ci        return name == rhs.name && age == rhs.age && metadata == rhs.metadata;
87c5f01b2fSopenharmony_ci    }
88c5f01b2fSopenharmony_ci
89c5f01b2fSopenharmony_ci    person_without_private_data_1() = default;
90c5f01b2fSopenharmony_ci    person_without_private_data_1(std::string name_, int age_, json metadata_)
91c5f01b2fSopenharmony_ci        : name(std::move(name_))
92c5f01b2fSopenharmony_ci        , age(age_)
93c5f01b2fSopenharmony_ci        , metadata(std::move(metadata_))
94c5f01b2fSopenharmony_ci    {}
95c5f01b2fSopenharmony_ci
96c5f01b2fSopenharmony_ci    NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_without_private_data_1, age, name, metadata)
97c5f01b2fSopenharmony_ci};
98c5f01b2fSopenharmony_ci
99c5f01b2fSopenharmony_ciclass person_without_private_data_2
100c5f01b2fSopenharmony_ci{
101c5f01b2fSopenharmony_ci  public:
102c5f01b2fSopenharmony_ci    std::string name{};
103c5f01b2fSopenharmony_ci    int age = 0;
104c5f01b2fSopenharmony_ci    json metadata = nullptr;
105c5f01b2fSopenharmony_ci
106c5f01b2fSopenharmony_ci    bool operator==(const person_without_private_data_2& rhs) const
107c5f01b2fSopenharmony_ci    {
108c5f01b2fSopenharmony_ci        return name == rhs.name && age == rhs.age && metadata == rhs.metadata;
109c5f01b2fSopenharmony_ci    }
110c5f01b2fSopenharmony_ci
111c5f01b2fSopenharmony_ci    person_without_private_data_2() = default;
112c5f01b2fSopenharmony_ci    person_without_private_data_2(std::string name_, int age_, json metadata_)
113c5f01b2fSopenharmony_ci        : name(std::move(name_))
114c5f01b2fSopenharmony_ci        , age(age_)
115c5f01b2fSopenharmony_ci        , metadata(std::move(metadata_))
116c5f01b2fSopenharmony_ci    {}
117c5f01b2fSopenharmony_ci};
118c5f01b2fSopenharmony_ci
119c5f01b2fSopenharmony_ciNLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_without_private_data_2, age, name, metadata)
120c5f01b2fSopenharmony_ci
121c5f01b2fSopenharmony_ciclass person_without_private_data_3
122c5f01b2fSopenharmony_ci{
123c5f01b2fSopenharmony_ci  public:
124c5f01b2fSopenharmony_ci    std::string name{};
125c5f01b2fSopenharmony_ci    int age = 0;
126c5f01b2fSopenharmony_ci    json metadata = nullptr;
127c5f01b2fSopenharmony_ci
128c5f01b2fSopenharmony_ci    bool operator==(const person_without_private_data_3& rhs) const
129c5f01b2fSopenharmony_ci    {
130c5f01b2fSopenharmony_ci        return name == rhs.name && age == rhs.age && metadata == rhs.metadata;
131c5f01b2fSopenharmony_ci    }
132c5f01b2fSopenharmony_ci
133c5f01b2fSopenharmony_ci    person_without_private_data_3() = default;
134c5f01b2fSopenharmony_ci    person_without_private_data_3(std::string name_, int age_, json metadata_)
135c5f01b2fSopenharmony_ci        : name(std::move(name_))
136c5f01b2fSopenharmony_ci        , age(age_)
137c5f01b2fSopenharmony_ci        , metadata(std::move(metadata_))
138c5f01b2fSopenharmony_ci    {}
139c5f01b2fSopenharmony_ci
140c5f01b2fSopenharmony_ci    std::string getName() const
141c5f01b2fSopenharmony_ci    {
142c5f01b2fSopenharmony_ci        return name;
143c5f01b2fSopenharmony_ci    }
144c5f01b2fSopenharmony_ci    int getAge() const
145c5f01b2fSopenharmony_ci    {
146c5f01b2fSopenharmony_ci        return age;
147c5f01b2fSopenharmony_ci    }
148c5f01b2fSopenharmony_ci    json getMetadata() const
149c5f01b2fSopenharmony_ci    {
150c5f01b2fSopenharmony_ci        return metadata;
151c5f01b2fSopenharmony_ci    }
152c5f01b2fSopenharmony_ci};
153c5f01b2fSopenharmony_ci
154c5f01b2fSopenharmony_ciNLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(person_without_private_data_3, age, name, metadata)
155c5f01b2fSopenharmony_ci
156c5f01b2fSopenharmony_ciclass person_with_private_alphabet
157c5f01b2fSopenharmony_ci{
158c5f01b2fSopenharmony_ci  public:
159c5f01b2fSopenharmony_ci    bool operator==(const person_with_private_alphabet& other) const
160c5f01b2fSopenharmony_ci    {
161c5f01b2fSopenharmony_ci        return  a == other.a &&
162c5f01b2fSopenharmony_ci                b == other.b &&
163c5f01b2fSopenharmony_ci                c == other.c &&
164c5f01b2fSopenharmony_ci                d == other.d &&
165c5f01b2fSopenharmony_ci                e == other.e &&
166c5f01b2fSopenharmony_ci                f == other.f &&
167c5f01b2fSopenharmony_ci                g == other.g &&
168c5f01b2fSopenharmony_ci                h == other.h &&
169c5f01b2fSopenharmony_ci                i == other.i &&
170c5f01b2fSopenharmony_ci                j == other.j &&
171c5f01b2fSopenharmony_ci                k == other.k &&
172c5f01b2fSopenharmony_ci                l == other.l &&
173c5f01b2fSopenharmony_ci                m == other.m &&
174c5f01b2fSopenharmony_ci                n == other.n &&
175c5f01b2fSopenharmony_ci                o == other.o &&
176c5f01b2fSopenharmony_ci                p == other.p &&
177c5f01b2fSopenharmony_ci                q == other.q &&
178c5f01b2fSopenharmony_ci                r == other.r &&
179c5f01b2fSopenharmony_ci                s == other.s &&
180c5f01b2fSopenharmony_ci                t == other.t &&
181c5f01b2fSopenharmony_ci                u == other.u &&
182c5f01b2fSopenharmony_ci                v == other.v &&
183c5f01b2fSopenharmony_ci                w == other.w &&
184c5f01b2fSopenharmony_ci                x == other.x &&
185c5f01b2fSopenharmony_ci                y == other.y &&
186c5f01b2fSopenharmony_ci                z == other.z;
187c5f01b2fSopenharmony_ci    }
188c5f01b2fSopenharmony_ci
189c5f01b2fSopenharmony_ci  private:
190c5f01b2fSopenharmony_ci    int a = 0;
191c5f01b2fSopenharmony_ci    int b = 0;
192c5f01b2fSopenharmony_ci    int c = 0;
193c5f01b2fSopenharmony_ci    int d = 0;
194c5f01b2fSopenharmony_ci    int e = 0;
195c5f01b2fSopenharmony_ci    int f = 0;
196c5f01b2fSopenharmony_ci    int g = 0;
197c5f01b2fSopenharmony_ci    int h = 0;
198c5f01b2fSopenharmony_ci    int i = 0;
199c5f01b2fSopenharmony_ci    int j = 0;
200c5f01b2fSopenharmony_ci    int k = 0;
201c5f01b2fSopenharmony_ci    int l = 0;
202c5f01b2fSopenharmony_ci    int m = 0;
203c5f01b2fSopenharmony_ci    int n = 0;
204c5f01b2fSopenharmony_ci    int o = 0;
205c5f01b2fSopenharmony_ci    int p = 0;
206c5f01b2fSopenharmony_ci    int q = 0;
207c5f01b2fSopenharmony_ci    int r = 0;
208c5f01b2fSopenharmony_ci    int s = 0;
209c5f01b2fSopenharmony_ci    int t = 0;
210c5f01b2fSopenharmony_ci    int u = 0;
211c5f01b2fSopenharmony_ci    int v = 0;
212c5f01b2fSopenharmony_ci    int w = 0;
213c5f01b2fSopenharmony_ci    int x = 0;
214c5f01b2fSopenharmony_ci    int y = 0;
215c5f01b2fSopenharmony_ci    int z = 0;
216c5f01b2fSopenharmony_ci    NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
217c5f01b2fSopenharmony_ci};
218c5f01b2fSopenharmony_ci
219c5f01b2fSopenharmony_ciclass person_with_public_alphabet
220c5f01b2fSopenharmony_ci{
221c5f01b2fSopenharmony_ci  public:
222c5f01b2fSopenharmony_ci    bool operator==(const person_with_public_alphabet& other) const
223c5f01b2fSopenharmony_ci    {
224c5f01b2fSopenharmony_ci        return  a == other.a &&
225c5f01b2fSopenharmony_ci                b == other.b &&
226c5f01b2fSopenharmony_ci                c == other.c &&
227c5f01b2fSopenharmony_ci                d == other.d &&
228c5f01b2fSopenharmony_ci                e == other.e &&
229c5f01b2fSopenharmony_ci                f == other.f &&
230c5f01b2fSopenharmony_ci                g == other.g &&
231c5f01b2fSopenharmony_ci                h == other.h &&
232c5f01b2fSopenharmony_ci                i == other.i &&
233c5f01b2fSopenharmony_ci                j == other.j &&
234c5f01b2fSopenharmony_ci                k == other.k &&
235c5f01b2fSopenharmony_ci                l == other.l &&
236c5f01b2fSopenharmony_ci                m == other.m &&
237c5f01b2fSopenharmony_ci                n == other.n &&
238c5f01b2fSopenharmony_ci                o == other.o &&
239c5f01b2fSopenharmony_ci                p == other.p &&
240c5f01b2fSopenharmony_ci                q == other.q &&
241c5f01b2fSopenharmony_ci                r == other.r &&
242c5f01b2fSopenharmony_ci                s == other.s &&
243c5f01b2fSopenharmony_ci                t == other.t &&
244c5f01b2fSopenharmony_ci                u == other.u &&
245c5f01b2fSopenharmony_ci                v == other.v &&
246c5f01b2fSopenharmony_ci                w == other.w &&
247c5f01b2fSopenharmony_ci                x == other.x &&
248c5f01b2fSopenharmony_ci                y == other.y &&
249c5f01b2fSopenharmony_ci                z == other.z;
250c5f01b2fSopenharmony_ci    }
251c5f01b2fSopenharmony_ci
252c5f01b2fSopenharmony_ci    int a = 0;
253c5f01b2fSopenharmony_ci    int b = 0;
254c5f01b2fSopenharmony_ci    int c = 0;
255c5f01b2fSopenharmony_ci    int d = 0;
256c5f01b2fSopenharmony_ci    int e = 0;
257c5f01b2fSopenharmony_ci    int f = 0;
258c5f01b2fSopenharmony_ci    int g = 0;
259c5f01b2fSopenharmony_ci    int h = 0;
260c5f01b2fSopenharmony_ci    int i = 0;
261c5f01b2fSopenharmony_ci    int j = 0;
262c5f01b2fSopenharmony_ci    int k = 0;
263c5f01b2fSopenharmony_ci    int l = 0;
264c5f01b2fSopenharmony_ci    int m = 0;
265c5f01b2fSopenharmony_ci    int n = 0;
266c5f01b2fSopenharmony_ci    int o = 0;
267c5f01b2fSopenharmony_ci    int p = 0;
268c5f01b2fSopenharmony_ci    int q = 0;
269c5f01b2fSopenharmony_ci    int r = 0;
270c5f01b2fSopenharmony_ci    int s = 0;
271c5f01b2fSopenharmony_ci    int t = 0;
272c5f01b2fSopenharmony_ci    int u = 0;
273c5f01b2fSopenharmony_ci    int v = 0;
274c5f01b2fSopenharmony_ci    int w = 0;
275c5f01b2fSopenharmony_ci    int x = 0;
276c5f01b2fSopenharmony_ci    int y = 0;
277c5f01b2fSopenharmony_ci    int z = 0;
278c5f01b2fSopenharmony_ci};
279c5f01b2fSopenharmony_ci
280c5f01b2fSopenharmony_ciNLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_with_public_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
281c5f01b2fSopenharmony_ci
282c5f01b2fSopenharmony_ci} // namespace persons
283c5f01b2fSopenharmony_ci
284c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T,
285c5f01b2fSopenharmony_ci                   persons::person_with_private_data,
286c5f01b2fSopenharmony_ci                   persons::person_without_private_data_1,
287c5f01b2fSopenharmony_ci                   persons::person_without_private_data_2)
288c5f01b2fSopenharmony_ci{
289c5f01b2fSopenharmony_ci    SECTION("person")
290c5f01b2fSopenharmony_ci    {
291c5f01b2fSopenharmony_ci        // serialization
292c5f01b2fSopenharmony_ci        T p1("Erik", 1, {{"haircuts", 2}});
293c5f01b2fSopenharmony_ci        CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
294c5f01b2fSopenharmony_ci
295c5f01b2fSopenharmony_ci        // deserialization
296c5f01b2fSopenharmony_ci        auto p2 = json(p1).get<T>();
297c5f01b2fSopenharmony_ci        CHECK(p2 == p1);
298c5f01b2fSopenharmony_ci
299c5f01b2fSopenharmony_ci        // roundtrip
300c5f01b2fSopenharmony_ci        CHECK(T(json(p1)) == p1);
301c5f01b2fSopenharmony_ci        CHECK(json(T(json(p1))) == json(p1));
302c5f01b2fSopenharmony_ci
303c5f01b2fSopenharmony_ci        // check exception in case of missing field
304c5f01b2fSopenharmony_ci        json j = json(p1);
305c5f01b2fSopenharmony_ci        j.erase("age");
306c5f01b2fSopenharmony_ci        CHECK_THROWS_WITH_AS(j.get<T>(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range);
307c5f01b2fSopenharmony_ci    }
308c5f01b2fSopenharmony_ci}
309c5f01b2fSopenharmony_ci
310c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T,
311c5f01b2fSopenharmony_ci                   persons::person_with_private_data_2,
312c5f01b2fSopenharmony_ci                   persons::person_without_private_data_3)
313c5f01b2fSopenharmony_ci{
314c5f01b2fSopenharmony_ci    SECTION("person with default values")
315c5f01b2fSopenharmony_ci    {
316c5f01b2fSopenharmony_ci        // serialization of default constructed object
317c5f01b2fSopenharmony_ci        T p0;
318c5f01b2fSopenharmony_ci        CHECK(json(p0).dump() == "{\"age\":0,\"metadata\":null,\"name\":\"\"}");
319c5f01b2fSopenharmony_ci
320c5f01b2fSopenharmony_ci        // serialization
321c5f01b2fSopenharmony_ci        T p1("Erik", 1, {{"haircuts", 2}});
322c5f01b2fSopenharmony_ci        CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
323c5f01b2fSopenharmony_ci
324c5f01b2fSopenharmony_ci        // deserialization
325c5f01b2fSopenharmony_ci        auto p2 = json(p1).get<T>();
326c5f01b2fSopenharmony_ci        CHECK(p2 == p1);
327c5f01b2fSopenharmony_ci
328c5f01b2fSopenharmony_ci        // roundtrip
329c5f01b2fSopenharmony_ci        CHECK(T(json(p1)) == p1);
330c5f01b2fSopenharmony_ci        CHECK(json(T(json(p1))) == json(p1));
331c5f01b2fSopenharmony_ci
332c5f01b2fSopenharmony_ci        // check default value in case of missing field
333c5f01b2fSopenharmony_ci        json j = json(p1);
334c5f01b2fSopenharmony_ci        j.erase("name");
335c5f01b2fSopenharmony_ci        j.erase("age");
336c5f01b2fSopenharmony_ci        j.erase("metadata");
337c5f01b2fSopenharmony_ci        T p3 = j.get<T>();
338c5f01b2fSopenharmony_ci        CHECK(p3.getName() == "");
339c5f01b2fSopenharmony_ci        CHECK(p3.getAge() == 0);
340c5f01b2fSopenharmony_ci        CHECK(p3.getMetadata() == nullptr);
341c5f01b2fSopenharmony_ci    }
342c5f01b2fSopenharmony_ci}
343c5f01b2fSopenharmony_ci
344c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T,
345c5f01b2fSopenharmony_ci                   persons::person_with_private_alphabet,
346c5f01b2fSopenharmony_ci                   persons::person_with_public_alphabet)
347c5f01b2fSopenharmony_ci{
348c5f01b2fSopenharmony_ci    SECTION("alphabet")
349c5f01b2fSopenharmony_ci    {
350c5f01b2fSopenharmony_ci        {
351c5f01b2fSopenharmony_ci            T obj1;
352c5f01b2fSopenharmony_ci            nlohmann::json j = obj1; //via json object
353c5f01b2fSopenharmony_ci            T obj2;
354c5f01b2fSopenharmony_ci            j.get_to(obj2);
355c5f01b2fSopenharmony_ci            bool ok = (obj1 == obj2);
356c5f01b2fSopenharmony_ci            CHECK(ok);
357c5f01b2fSopenharmony_ci        }
358c5f01b2fSopenharmony_ci
359c5f01b2fSopenharmony_ci        {
360c5f01b2fSopenharmony_ci            T obj1;
361c5f01b2fSopenharmony_ci            nlohmann::json j1 = obj1; //via json string
362c5f01b2fSopenharmony_ci            std::string s = j1.dump();
363c5f01b2fSopenharmony_ci            nlohmann::json j2 = nlohmann::json::parse(s);
364c5f01b2fSopenharmony_ci            T obj2;
365c5f01b2fSopenharmony_ci            j2.get_to(obj2);
366c5f01b2fSopenharmony_ci            bool ok = (obj1 == obj2);
367c5f01b2fSopenharmony_ci            CHECK(ok);
368c5f01b2fSopenharmony_ci        }
369c5f01b2fSopenharmony_ci
370c5f01b2fSopenharmony_ci        {
371c5f01b2fSopenharmony_ci            T obj1;
372c5f01b2fSopenharmony_ci            nlohmann::json j1 = obj1; //via msgpack
373c5f01b2fSopenharmony_ci            std::vector<uint8_t> buf = nlohmann::json::to_msgpack(j1);
374c5f01b2fSopenharmony_ci            nlohmann::json j2 = nlohmann::json::from_msgpack(buf);
375c5f01b2fSopenharmony_ci            T obj2;
376c5f01b2fSopenharmony_ci            j2.get_to(obj2);
377c5f01b2fSopenharmony_ci            bool ok = (obj1 == obj2);
378c5f01b2fSopenharmony_ci            CHECK(ok);
379c5f01b2fSopenharmony_ci        }
380c5f01b2fSopenharmony_ci
381c5f01b2fSopenharmony_ci        {
382c5f01b2fSopenharmony_ci            T obj1;
383c5f01b2fSopenharmony_ci            nlohmann::json j1 = obj1; //via bson
384c5f01b2fSopenharmony_ci            std::vector<uint8_t> buf = nlohmann::json::to_bson(j1);
385c5f01b2fSopenharmony_ci            nlohmann::json j2 = nlohmann::json::from_bson(buf);
386c5f01b2fSopenharmony_ci            T obj2;
387c5f01b2fSopenharmony_ci            j2.get_to(obj2);
388c5f01b2fSopenharmony_ci            bool ok = (obj1 == obj2);
389c5f01b2fSopenharmony_ci            CHECK(ok);
390c5f01b2fSopenharmony_ci        }
391c5f01b2fSopenharmony_ci
392c5f01b2fSopenharmony_ci        {
393c5f01b2fSopenharmony_ci            T obj1;
394c5f01b2fSopenharmony_ci            nlohmann::json j1 = obj1; //via cbor
395c5f01b2fSopenharmony_ci            std::vector<uint8_t> buf = nlohmann::json::to_cbor(j1);
396c5f01b2fSopenharmony_ci            nlohmann::json j2 = nlohmann::json::from_cbor(buf);
397c5f01b2fSopenharmony_ci            T obj2;
398c5f01b2fSopenharmony_ci            j2.get_to(obj2);
399c5f01b2fSopenharmony_ci            bool ok = (obj1 == obj2);
400c5f01b2fSopenharmony_ci            CHECK(ok);
401c5f01b2fSopenharmony_ci        }
402c5f01b2fSopenharmony_ci
403c5f01b2fSopenharmony_ci        {
404c5f01b2fSopenharmony_ci            T obj1;
405c5f01b2fSopenharmony_ci            nlohmann::json j1 = obj1; //via ubjson
406c5f01b2fSopenharmony_ci            std::vector<uint8_t> buf = nlohmann::json::to_ubjson(j1);
407c5f01b2fSopenharmony_ci            nlohmann::json j2 = nlohmann::json::from_ubjson(buf);
408c5f01b2fSopenharmony_ci            T obj2;
409c5f01b2fSopenharmony_ci            j2.get_to(obj2);
410c5f01b2fSopenharmony_ci            bool ok = (obj1 == obj2);
411c5f01b2fSopenharmony_ci            CHECK(ok);
412c5f01b2fSopenharmony_ci        }
413c5f01b2fSopenharmony_ci    }
414c5f01b2fSopenharmony_ci}
415