You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "szaszm (via GitHub)" <gi...@apache.org> on 2023/04/11 13:22:05 UTC

[GitHub] [nifi-minifi-cpp] szaszm commented on a diff in pull request #1552: MINIFICPP-2089 prefix EventData in flat JSON output so it doesnt need t…

szaszm commented on code in PR #1552:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1552#discussion_r1162810078


##########
extensions/windows-event-log/wel/JSONUtils.cpp:
##########
@@ -135,28 +157,37 @@ rapidjson::Document toJSONImpl(const pugi::xml_node& root, bool flatten) {
 
   {
     auto eventData_xml = event_xml.child("EventData");
-    // create EventData subarray even if flatten requested
-    doc.AddMember("EventData", rapidjson::kArrayType, doc.GetAllocator());
-    for (const auto& data : eventData_xml.children()) {
-      auto name_attr = data.attribute("Name");
-      rapidjson::Value item(rapidjson::kObjectType);
-      item.AddMember("Name", rapidjson::StringRef(name_attr.value()), doc.GetAllocator());
-      item.AddMember("Content", rapidjson::StringRef(data.text().get()), doc.GetAllocator());
-      item.AddMember("Type", rapidjson::StringRef(data.name()), doc.GetAllocator());
-      // we need to query EventData because a reference to it wouldn't be stable, as we
-      // possibly add members to its parent which could result in reallocation
-      doc["EventData"].PushBack(item, doc.GetAllocator());
-      // check collision
-      if (flatten && !name_attr.empty() && !doc.HasMember(name_attr.value())) {
-        doc.AddMember(rapidjson::StringRef(name_attr.value()), rapidjson::StringRef(data.text().get()), doc.GetAllocator());
+    if (flatten) {
+      for (const auto& event_data_child : eventData_xml.children()) {
+        std::string key = "EventData";
+        if (auto name_attr = event_data_child.attribute("Name").value(); strlen(name_attr)) {
+          key = utils::StringUtils::join_pack(key, ".", name_attr);
+        }
+
+        if (auto type = event_data_child.name(); strlen(type) > 0) {
+          key = utils::StringUtils::join_pack(key, ".", type);
+        }
+
+        doc.AddMember(rapidjson::Value(createUniqueKey(key, doc), doc.GetAllocator()).Move(), rapidjson::StringRef(event_data_child.text().get()), doc.GetAllocator());
+      }
+    } else {
+      auto& event_data = doc.AddMember("EventData", rapidjson::kArrayType, doc.GetAllocator());
+      for (const auto& event_data_child : eventData_xml.children()) {
+        auto name_attr = event_data_child.attribute("Name");
+        rapidjson::Value item(rapidjson::kObjectType);
+        item.AddMember("Name", rapidjson::StringRef(name_attr.value()), doc.GetAllocator());
+        item.AddMember("Content", rapidjson::StringRef(event_data_child.text().get()), doc.GetAllocator());
+        item.AddMember("Type", rapidjson::StringRef(event_data_child.name()), doc.GetAllocator());
+        doc["EventData"].PushBack(item, doc.GetAllocator());

Review Comment:
   Could we change the format to avoid a subobject for all custom values? So instead of this:
   ```json
   "EventData": [{
       "Name": "Foobar",
       "Content": "Lorem ipsum",
       "Type": "Text"
   }]
   ```
   
   something like this:
   ```json
   "EventData": {
       "Foobar": "Lorem ipsum"
   }
   ```



##########
CMakeLists.txt:
##########
@@ -288,6 +288,7 @@ target_include_directories(concurrentqueue SYSTEM INTERFACE "${CMAKE_CURRENT_SOU
 # RapidJSON
 add_library(RapidJSON INTERFACE)
 target_include_directories(RapidJSON SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/rapidjson-48fbd8cd202ca54031fe799db2ad44ffa8e77c13/include")
+target_compile_definitions(RapidJSON INTERFACE RAPIDJSON_HAS_STDSTRING)

Review Comment:
   Is this an interface-only change, or does it require RapidJSON recompilation? (e.g. missing related symbols)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org