Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/Json/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,42 @@ size_t Printer::operator()()
n += p->print(isArray ? '[' : '{');
}

// Print child object
auto objectCount = object.getObjectCount();
if(index < objectCount) {
auto obj = object.getObject(index);
// Print property
auto propertyCount = object.getPropertyCount();
if(index < propertyCount) {
auto prop = static_cast<const Object&>(object).getProperty(index);
if(object.streamPos++) {
n += p->print(',');
}
n += newline();
if(pretty && object.typeIs(ObjectType::ObjectArray)) {
if(pretty) {
n += p->print(indent);
n += p->print(" ");
}
++nesting;
objects[nesting] = obj;
if(prop.info().name.length()) {
n += p->print(quote(prop.info().name));
n += p->print(colon);
}
n += p->print(prop.getJsonValue());
return n;
}

index -= objectCount;
index -= propertyCount;

// Print property
if(index < object.getPropertyCount()) {
auto prop = static_cast<const Object&>(object).getProperty(index);
// Print child object
auto objectCount = object.getObjectCount();
if(index < objectCount) {
auto obj = object.getObject(index);
if(object.streamPos++) {
n += p->print(',');
}
n += newline();
if(pretty) {
if(pretty && object.typeIs(ObjectType::ObjectArray)) {
n += p->print(indent);
n += p->print(" ");
}
if(prop.info().name.length()) {
n += p->print(quote(prop.info().name));
n += p->print(colon);
}
n += p->print(prop.getJsonValue());
++nesting;
objects[nesting] = obj;
return n;
}

Expand Down
12 changes: 4 additions & 8 deletions test/modules/Streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace json
IMPORT_FSTR_LOCAL(update1, PROJECT_DIR "/resource/update1.json")
IMPORT_FSTR_LOCAL(root1, PROJECT_DIR "/resource/root1.json")
IMPORT_FSTR_LOCAL(database1, PROJECT_DIR "/resource/database1.json")
IMPORT_FSTR_LOCAL(export_root, PROJECT_DIR "/resource/export-root.json")
IMPORT_FSTR_LOCAL(array_test_default, PROJECT_DIR "/resource/array_test_default.json")
IMPORT_FSTR_LOCAL(async_update, PROJECT_DIR "/resource/async-update.json")
IMPORT_FSTR_LOCAL(async_update_result, PROJECT_DIR "/resource/async-update-result.json")
Expand Down Expand Up @@ -143,18 +144,13 @@ class StreamingTest : public TestGroup
TEST_CASE("Streaming export options (root)")
{
// An un-named root object should produce same output (i.e. options are ignored)
String expectedContent =
F("{\"simple-union\":{\"obj2\":{\"value\":12}},\"int_array\":[13,28,39,40],\"string_array\":[\"a\","
"\"b\",\"c\"],\"object_array\":[],\"color\":"
"\"red\",\"simple-bool\":true,\"simple-string\":\"donkey\",\"simple-int\":100,\"simple-float\":3."
"1415927}");
TestConfig::Root root(database);
auto stream = root.createExportStream(ConfigDB::Json::format);
REQUIRE_EQ(getContent(*stream), expectedContent);
REQUIRE_EQ(getContent(*stream), json::export_root);
stream = root.createExportStream(ConfigDB::Json::format, {.useName = true});
REQUIRE_EQ(getContent(*stream), expectedContent);
REQUIRE_EQ(getContent(*stream), json::export_root);
stream = root.createExportStream(ConfigDB::Json::format, {.asObject = true});
REQUIRE_EQ(getContent(*stream), expectedContent);
REQUIRE_EQ(getContent(*stream), json::export_root);
}

TEST_CASE("Streaming export options (database)")
Expand Down
2 changes: 1 addition & 1 deletion test/modules/Union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class UnionTest : public TestGroup

TEST_CASE("Root Union")
{
DEFINE_FSTR_LOCAL(expectedRequest, "{\"request\":{\"args\":[\"all\"],\"method\":\"query\"}}")
DEFINE_FSTR_LOCAL(expectedRequest, "{\"request\":{\"method\":\"query\",\"args\":[\"all\"]}}")
DEFINE_FSTR_LOCAL(expectedResponse, "{\"response\":{\"code\":-1,\"message\":\"undefined\"}}")
TestRootUnion db("dummy");
TestRootUnion::Root root(db);
Expand Down
2 changes: 1 addition & 1 deletion test/resource/async-update-result.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"simple-union":{"obj1":{"value":0}},"int_array":[100,1],"string_array":["go","away"],"object_array":[{"intval":1,"stringval":"biscuit"},{"intval":2,"stringval":"cake"}],"color":"green","simple-bool":true,"simple-string":"gorilla","simple-int":100,"simple-float":1.2e8}
{"color":"green","simple-bool":true,"simple-string":"gorilla","simple-int":100,"simple-float":1.2e8,"simple-union":{"obj1":{"value":0}},"int_array":[100,1],"string_array":["go","away"],"object_array":[{"intval":1,"stringval":"biscuit"},{"intval":2,"stringval":"cake"}]}
2 changes: 1 addition & 1 deletion test/resource/database1.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927,"array-store":[],"object-array-store":[]}
{"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927,"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"array-store":[],"object-array-store":[]}
1 change: 1 addition & 0 deletions test/resource/export-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927,"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[]}
2 changes: 1 addition & 1 deletion test/resource/root1.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927}
{"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927,"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[]}
Loading