[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 bb71962..03e448f 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 a2809c5..a3d8df4 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;