summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-06 20:25:26 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-06 20:28:02 +0100
commit7cb938a227979d66b58685b2199a86e6bff9b046 (patch)
treeac8dc5b7515b53abdf700eb6a1c198dd97bfb8fa
parentMove private stuff into anon namespace (diff)
downloadslicer-7cb938a227979d66b58685b2199a86e6bff9b046.tar.bz2
slicer-7cb938a227979d66b58685b2199a86e6bff9b046.tar.xz
slicer-7cb938a227979d66b58685b2199a86e6bff9b046.zip
Fix implementation of json dictionary serialize in non-object mode
-rw-r--r--slicer/json/serializer.cpp4
-rw-r--r--slicer/test/serializers.cpp12
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(