mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 02:18:04 +01:00
stringify method output wrong json string #891
This commit is contained in:
@@ -32,33 +32,35 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
|
|||||||
{
|
{
|
||||||
if (step == -1) step = indent;
|
if (step == -1) step = indent;
|
||||||
|
|
||||||
if ( any.type() == typeid(Object) )
|
if (any.type() == typeid(Object))
|
||||||
{
|
{
|
||||||
const Object& o = any.extract<Object>();
|
const Object& o = any.extract<Object>();
|
||||||
o.stringify(out, indent == 0 ? 0 : indent, step);
|
o.stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if ( any.type() == typeid(Array) )
|
else if (any.type() == typeid(Array))
|
||||||
{
|
{
|
||||||
const Array& a = any.extract<Array>();
|
const Array& a = any.extract<Array>();
|
||||||
a.stringify(out, indent == 0 ? 0 : indent, step);
|
a.stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if ( any.type() == typeid(Object::Ptr) )
|
else if (any.type() == typeid(Object::Ptr))
|
||||||
{
|
{
|
||||||
const Object::Ptr& o = any.extract<Object::Ptr>();
|
const Object::Ptr& o = any.extract<Object::Ptr>();
|
||||||
o->stringify(out, indent == 0 ? 0 : indent, step);
|
o->stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if ( any.type() == typeid(Array::Ptr) )
|
else if (any.type() == typeid(Array::Ptr))
|
||||||
{
|
{
|
||||||
const Array::Ptr& a = any.extract<Array::Ptr>();
|
const Array::Ptr& a = any.extract<Array::Ptr>();
|
||||||
a->stringify(out, indent == 0 ? 0 : indent, step);
|
a->stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if ( any.isEmpty() )
|
else if (any.isEmpty())
|
||||||
{
|
{
|
||||||
out << "null";
|
out << "null";
|
||||||
}
|
}
|
||||||
else if ( any.isNumeric() || any.isBoolean() )
|
else if (any.isNumeric() || any.isBoolean())
|
||||||
{
|
{
|
||||||
out << any.convert<std::string>();
|
std::string value = any.convert<std::string>();
|
||||||
|
if (any.type() == typeid(char)) formatString(value, out);
|
||||||
|
else out << value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -322,6 +322,11 @@ void JSONTest::testStringProperty()
|
|||||||
std::string value = test.convert<std::string>();
|
std::string value = test.convert<std::string>();
|
||||||
assert(value.compare("value") == 0);
|
assert(value.compare("value") == 0);
|
||||||
|
|
||||||
|
object.set("test2", 'a');
|
||||||
|
std::ostringstream ostr;
|
||||||
|
object.stringify(ostr);
|
||||||
|
assert(ostr.str() == "{\"test\":\"value\",\"test2\":\"a\"}");
|
||||||
|
|
||||||
DynamicStruct ds = object;
|
DynamicStruct ds = object;
|
||||||
assert (!ds["test"].isEmpty());
|
assert (!ds["test"].isEmpty());
|
||||||
assert (ds["test"].isString());
|
assert (ds["test"].isString());
|
||||||
|
|||||||
Reference in New Issue
Block a user