From 7cb938a227979d66b58685b2199a86e6bff9b046 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Aug 2023 20:25:26 +0100 Subject: Fix implementation of json dictionary serialize in non-object mode --- slicer/json/serializer.cpp | 4 ++-- 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()](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(1, 2); + d[2] = std::make_shared(3, 4); + d[3] = std::make_shared(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( -- cgit v1.2.3