diff --git a/JSON/include/Poco/JSON/Array.h b/JSON/include/Poco/JSON/Array.h index 32f5443df..8fa45786c 100644 --- a/JSON/include/Poco/JSON/Array.h +++ b/JSON/include/Poco/JSON/Array.h @@ -379,7 +379,7 @@ public: void convert(std::string& s) const { std::ostringstream oss; - _val->stringify(oss, 2); + _val->stringify(oss); s = oss.str(); } @@ -513,7 +513,7 @@ public: void convert(std::string& s) const { std::ostringstream oss; - _val.stringify(oss, 2); + _val.stringify(oss); s = oss.str(); } diff --git a/JSON/include/Poco/JSON/Object.h b/JSON/include/Poco/JSON/Object.h index 833e355b0..5a3cd688c 100644 --- a/JSON/include/Poco/JSON/Object.h +++ b/JSON/include/Poco/JSON/Object.h @@ -570,7 +570,7 @@ public: void convert(std::string& s) const { std::ostringstream oss; - _val->stringify(oss, 2); + _val->stringify(oss); s = oss.str(); } @@ -712,7 +712,7 @@ public: void convert(std::string& s) const { std::ostringstream oss; - _val.stringify(oss, 2); + _val.stringify(oss); s = oss.str(); } diff --git a/JSON/testsuite/src/JSONTest.cpp b/JSON/testsuite/src/JSONTest.cpp index 3cab104e0..51ce7510a 100644 --- a/JSON/testsuite/src/JSONTest.cpp +++ b/JSON/testsuite/src/JSONTest.cpp @@ -1701,6 +1701,43 @@ void JSONTest::testStringifyPreserveOrder() } +void JSONTest::testVarConvert() +{ + std::string json = "{ \"foo\" : { \"bar\" : \"baz\", \"arr\": [1, 2, 3]} }"; + Parser parser; + Var result; + + try + { + result = parser.parse(json); + } + catch (JSONException& jsone) + { + std::cout << jsone.message() << std::endl; + assertTrue(false); + } + + assertTrue(result.type() == typeid(Object::Ptr)); + + std::string cvt; + result.convert(cvt); + assertTrue(cvt == "{\"foo\":{\"arr\":[1,2,3],\"bar\":\"baz\"}}"); + + Object::Ptr object = result.extract(); + Object::Ptr f = object->getObject("foo"); + + Var o = f; + cvt.clear(); + o.convert(cvt); + assertTrue(cvt == "{\"arr\":[1,2,3],\"bar\":\"baz\"}"); + + Var a = f->get("arr"); + cvt.clear(); + a.convert(cvt); + assertTrue(cvt == "[1,2,3]"); +} + + void JSONTest::testValidJanssonFiles() { Poco::Path pathPattern(getTestFilesPath("valid")); @@ -2249,6 +2286,7 @@ CppUnit::Test* JSONTest::suite() CppUnit_addTest(pSuite, JSONTest, testPrintHandler); CppUnit_addTest(pSuite, JSONTest, testStringify); CppUnit_addTest(pSuite, JSONTest, testStringifyPreserveOrder); + CppUnit_addTest(pSuite, JSONTest, testVarConvert); CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles); CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles); CppUnit_addTest(pSuite, JSONTest, testInvalidUnicodeJanssonFiles); diff --git a/JSON/testsuite/src/JSONTest.h b/JSON/testsuite/src/JSONTest.h index 90482672f..f541d4499 100644 --- a/JSON/testsuite/src/JSONTest.h +++ b/JSON/testsuite/src/JSONTest.h @@ -68,6 +68,7 @@ public: void testPrintHandler(); void testStringify(); void testStringifyPreserveOrder(); + void testVarConvert(); void testValidJanssonFiles(); void testInvalidJanssonFiles();