Fixed UnitTest crash when getting JSON from blank object
authorErich Keane <erich.keane@intel.com>
Wed, 10 Dec 2014 21:52:15 +0000 (13:52 -0800)
committerErich Keane <erich.keane@intel.com>
Wed, 10 Dec 2014 21:52:15 +0000 (13:52 -0800)
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 <erich.keane@intel.com>
resource/src/OCRepresentation.cpp

index 460e9ac..6910baf 100644 (file)
@@ -33,7 +33,7 @@
 #include <OicJsonSerializer.hpp>
 #include <algorithm>
 
-// 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;
     }