[common] Native bundle to json converter. 86/206586/1
authorMichal Michalski <m.michalski2@partner.samsung.com>
Tue, 21 May 2019 13:26:11 +0000 (15:26 +0200)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Tue, 21 May 2019 13:26:11 +0000 (15:26 +0200)
Function which converts native bundle object into json.

[Verification] Code compiles without error.

Change-Id: I932971d40309017c7ba7be9d677a41147ac5b3c2
Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
src/common/json-utils.cc
src/common/json-utils.h

index bb719626977aa60a414d998ced640ea7497d156c..03e448f7a3570631e93c118b5461d71227ff271e 100644 (file)
@@ -36,6 +36,17 @@ PlatformResult JsonToBundle(const picojson::object& json, bundle* bundle_data) {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult BundleToJson(bundle* bundle_data, picojson::object* json) {
+    picojson::array array_data;
+    bundle_foreach(bundle_data, BundleJsonIterator, &array_data);
+
+    for (auto& elem: array_data) {
+        (*json)[elem.get("key").get<std::string>()] = elem.get("value");
+    }
+
+    return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 PlatformResult JsonToBundle(const picojson::array& json, bundle* bundle_data) {
   ScopeLogger();
   for (const auto& item: json) {
index a2809c52cf0974776896625a0cb4fd2380b72a55..a3d8df43fb49c4877e6d6880d0576a9da65e7f76 100644 (file)
@@ -27,6 +27,7 @@ namespace common {
 void BundleJsonIterator(const char* key, const int type, const bundle_keyval_t* kv, void* d);
 
 PlatformResult JsonToBundle(const picojson::object& json, bundle* bundle_data);
+PlatformResult BundleToJson(bundle* bundle_data, picojson::object* json);
 PlatformResult JsonToBundle(const picojson::array& json, bundle* bundle_data);
 
 } // namespace common;