diff --git a/include/rfl/parsing/Parser_shared_ptr.hpp b/include/rfl/parsing/Parser_shared_ptr.hpp index 60bb2e3a..cd29da63 100644 --- a/include/rfl/parsing/Parser_shared_ptr.hpp +++ b/include/rfl/parsing/Parser_shared_ptr.hpp @@ -12,8 +12,7 @@ #include "Parser_base.hpp" #include "schema/Type.hpp" -namespace rfl { -namespace parsing { +namespace rfl::parsing { template requires AreReaderAndWriter> @@ -25,7 +24,7 @@ struct Parser> { static Result> read(const R& _r, const InputVarType& _var) noexcept { - if (_r.is_empty(*_var)) { + if (_r.is_empty(_var)) { return std::shared_ptr(); } const auto to_ptr = [](auto&& _t) { @@ -53,7 +52,6 @@ struct Parser> { } }; -} // namespace parsing -} // namespace rfl +} // namespace rfl::parsing #endif diff --git a/tests/json/test_shared_ptr.cpp b/tests/json/test_shared_ptr.cpp new file mode 100644 index 00000000..71c44d18 --- /dev/null +++ b/tests/json/test_shared_ptr.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "test_unique_ptr.hpp" +#include "write_and_read.hpp" + +namespace test_shared_ptr { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::shared_ptr> children; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + auto children = std::make_shared>(); + 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_shared_ptr diff --git a/tests/json/test_shared_ptr.hpp b/tests/json/test_shared_ptr.hpp new file mode 100644 index 00000000..ac05afcf --- /dev/null +++ b/tests/json/test_shared_ptr.hpp @@ -0,0 +1,4 @@ +namespace test_shared_ptr { +void test(); +} + diff --git a/tests/json/tests.cpp b/tests/json/tests.cpp index 38cf2a4f..bd82b48c 100644 --- a/tests/json/tests.cpp +++ b/tests/json/tests.cpp @@ -64,6 +64,7 @@ #include "test_result.hpp" #include "test_save_load.hpp" #include "test_set.hpp" +#include "test_shared_ptr.hpp" #include "test_size.hpp" #include "test_std_ref.hpp" #include "test_string_map.hpp" @@ -89,6 +90,7 @@ int main() { test_optional_fields::test(); test_unique_ptr::test(); test_unique_ptr2::test(); + test_shared_ptr::test(); test_literal::test(); test_variant::test(); test_tagged_union::test();