From: Erich Keane Date: Wed, 10 Dec 2014 21:52:15 +0000 (-0800) Subject: Fixed UnitTest crash when getting JSON from blank object X-Git-Tag: 0.9.0-CM-RC1~16^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=acf70a88f0b75134a85fcac741dc832ec46c23d8;p=contrib%2Fiotivity.git Fixed UnitTest crash when getting JSON from blank object Generating a JSON representation from a blank object is an error condition, so we were crashing. The unit tests validated this situation, so this fix returns the correct value in that situation. Additionally corrected a comment highlighted in a previous review. Change-Id: I113bf0ad53bb939d90278928257ff7b56aa4959b Signed-off-by: Erich Keane --- diff --git a/resource/src/OCRepresentation.cpp b/resource/src/OCRepresentation.cpp index 460e9ac..6910baf 100644 --- a/resource/src/OCRepresentation.cpp +++ b/resource/src/OCRepresentation.cpp @@ -33,7 +33,7 @@ #include #include -// code needed to serialize a string::Attribute value map +// code needed to serialize a string=>Attribute value map namespace OC { namespace detail @@ -116,6 +116,11 @@ namespace OC std::string MessageContainer::getJSONRepresentation(OCInfoFormat f) const { + if(empty()) + { + return "{}"; + } + std::stringstream os; // note: the block is required because cereal closes the JSON string @@ -255,6 +260,11 @@ namespace OC return false; } + if(m_children.size() > 0) + { + return false; + } + return true; }