mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-27 21:36:19 +08:00
29 lines
897 B
C++
29 lines
897 B
C++
#include <rfl.hpp>
|
|
#include <rfl/json.hpp>
|
|
#include <string>
|
|
|
|
#include "write_and_read.hpp"
|
|
|
|
namespace test_list {
|
|
|
|
struct Person {
|
|
rfl::Rename<"firstName", std::string> first_name;
|
|
rfl::Rename<"lastName", std::string> last_name = "Simpson";
|
|
std::unique_ptr<std::list<Person>> children;
|
|
};
|
|
|
|
TEST(json, test_list) {
|
|
auto children = std::make_unique<std::list<Person>>();
|
|
children->emplace_back(Person{.first_name = "Bart"});
|
|
children->emplace_back(Person{.first_name = "Lisa"});
|
|
children->emplace_back(Person{.first_name = "Maggie"});
|
|
|
|
const auto homer =
|
|
Person{.first_name = "Homer", .children = std::move(children)};
|
|
|
|
write_and_read(
|
|
homer,
|
|
R"({"firstName":"Homer","lastName":"Simpson","children":[{"firstName":"Bart","lastName":"Simpson"},{"firstName":"Lisa","lastName":"Simpson"},{"firstName":"Maggie","lastName":"Simpson"}]})");
|
|
}
|
|
} // namespace test_list
|