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


##########
extensions/windows-event-log/wel/JSONUtils.cpp:
##########
@@ -135,28 +158,33 @@ 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);
+        }
+
+        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:
   For some reason the event_data reference is unstable (rapidjson probably 
reallocates when we add children to it) I've removed the event_data variable so 
it doesnt tempt us, and readded the comment that explains why in 
https://github.com/apache/nifi-minifi-cpp/pull/1552/commits/1aa0603b2118b0237fe0c90f085ca608c78bcbe6



-- 
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-unsubscr...@nifi.apache.org

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

Reply via email to