diff options
-rw-r--r-- | slicer/json/serializer.cpp | 4 | ||||
-rw-r--r-- | slicer/test/serializers.cpp | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index d9f7db8..6470df9 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -354,8 +354,8 @@ namespace Slicer { } else { *n = json::Array(); - mp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) { - return JsonSerializer::ModelTreeIterate(n, PH1, PH2); + mp->OnEachChild([&a = n->emplace<json::Array>()](auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateRoot(&a.emplace_back(), PH2); }); } break; diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index 5e643a9..6a41cdd 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -674,6 +674,18 @@ BOOST_AUTO_TEST_CASE(DeserializeXmlAbstractImpl) BOOST_CHECK_EQUAL("value", impl->testVal); } +BOOST_AUTO_TEST_CASE(SerializeJsonClassMap) +{ + TestModule::ClassMap d; + d[1] = std::make_shared<TestModule::ClassType>(1, 2); + d[2] = std::make_shared<TestModule::ClassType>(3, 4); + d[3] = std::make_shared<TestModule::ClassType>(5, 6); + std::stringstream out; + Slicer::SerializeAnyWith(d, Slicer::JsonStreamSerializer {out}); + BOOST_CHECK_EQUAL(out.view(), + R"([{"key":1,"value":{"a":1,"b":2}},{"key":2,"value":{"a":3,"b":4}},{"key":3,"value":{"a":5,"b":6}}])"); +} + BOOST_AUTO_TEST_CASE(DeserializeXmlIncorrectSeqElementName) { std::stringstream in(R"X( |