Skip to content

Commit

Permalink
stringify method output wrong json string pocoproject#891
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Jul 31, 2015
1 parent 04caf94 commit 08a85e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 9 additions & 7 deletions JSON/src/Stringifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,35 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
{
if (step == -1) step = indent;

if ( any.type() == typeid(Object) )
if (any.type() == typeid(Object))
{
const Object& o = any.extract<Object>();
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>();
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>();
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>();
a->stringify(out, indent == 0 ? 0 : indent, step);
}
else if ( any.isEmpty() )
else if (any.isEmpty())
{
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
{
Expand Down
5 changes: 5 additions & 0 deletions JSON/testsuite/src/JSONTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ void JSONTest::testStringProperty()
std::string value = test.convert<std::string>();
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;
assert (!ds["test"].isEmpty());
assert (ds["test"].isString());
Expand Down

0 comments on commit 08a85e8

Please sign in to comment.