You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "ChrisSamo632 (via GitHub)" <gi...@apache.org> on 2024/02/16 20:26:10 UTC

Re: [PR] NIFI-8134 allow unescapeJson Record Path function to recursively convert Maps to Records [nifi]

ChrisSamo632 commented on code in PR #7745:
URL: https://github.com/apache/nifi/pull/7745#discussion_r1420713574


##########
nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java:
##########
@@ -1837,7 +1838,41 @@ public void testUnescapeJson() {
                     put("firstName", "John");
                     put("age", 30);
                 }}, "json_str"),
-                RecordPath.compile("unescapeJson(/json_str, 'true')").evaluate(recordFromMap).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
+                RecordPath.compile("unescapeJson(/json_str, 'true')").evaluate(recordFromMap).getSelectedFields().findFirst().orElseThrow(AssertionError::new).getValue()
+        );
+
+        // test nested Record converted from Map Object
+        final Record nestedRecordFromMap = new MapRecord(schema,
+                Collections.singletonMap(
+                        "json_str",
+                        "{\"firstName\":\"John\",\"age\":30,\"addresses\":[{\"address_1\":\"123 Fake Street\"}]}")
+        );
+        // recursively convert Maps to Records (addresses becomes and ARRAY or RECORDs)
+        assertEquals(
+                DataTypeUtils.toRecord(new LinkedHashMap<String, Object>(){{
+                    put("firstName", "John");
+                    put("age", 30);
+                    put("addresses", new Object[] {DataTypeUtils.toRecord(Collections.singletonMap("address_1", "123 Fake Street"), "addresses")});
+                }}, "json_str"),

Review Comment:
   Absolutely. The only problem is that `Map.of` doesn't provide deterministic ordering, so we do need to use `LinkedHashMap`s in some places, which I've changed to use the approach suggested.



-- 
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