Repository: nifi
Updated Branches:
  refs/heads/master 11a7d5c09 -> 37ad48844


NIFI-4962 FlattenJson processor add unexpected backslash after flatten

Signed-off-by: Pierre Villard <pierre.villard...@gmail.com>

This closes #2538.


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/37ad4884
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/37ad4884
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/37ad4884

Branch: refs/heads/master
Commit: 37ad48844a61e7cecaf5650f2d3a4d6f02483d99
Parents: 11a7d5c
Author: Deon Huang <yjhyjhy...@gmail.com>
Authored: Wed Mar 14 00:04:29 2018 +0800
Committer: Pierre Villard <pierre.villard...@gmail.com>
Committed: Tue Mar 13 22:33:53 2018 +0100

----------------------------------------------------------------------
 .../nifi/processors/standard/FlattenJson.java    |  2 ++
 .../processors/standard/TestFlattenJson.groovy   | 19 +++++++++++++++++++
 nifi-nar-bundles/nifi-standard-bundle/pom.xml    |  2 +-
 3 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/37ad4884/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
index ed3c785..afb6747 100644
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
@@ -20,6 +20,7 @@ package org.apache.nifi.processors.standard;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.wnameless.json.flattener.FlattenMode;
 import com.github.wnameless.json.flattener.JsonFlattener;
+import org.apache.commons.text.StringEscapeUtils;
 import org.apache.nifi.annotation.behavior.SideEffectFree;
 import org.apache.nifi.annotation.documentation.CapabilityDescription;
 import org.apache.nifi.annotation.documentation.Tags;
@@ -160,6 +161,7 @@ public class FlattenJson extends AbstractProcessor {
             final String flattened = new JsonFlattener(raw)
                     .withFlattenMode(flattenMode)
                     .withSeparator(separator.charAt(0))
+                    .withStringEscapePolicy(() -> 
StringEscapeUtils.ESCAPE_JAVA)
                     .flatten();
 
             flowFile = session.write(flowFile, os -> 
os.write(flattened.getBytes()));

http://git-wip-us.apache.org/repos/asf/nifi/blob/37ad4884/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/TestFlattenJson.groovy
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/TestFlattenJson.groovy
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/TestFlattenJson.groovy
index 0b4a9c6..8eda11e 100644
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/TestFlattenJson.groovy
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/TestFlattenJson.groovy
@@ -172,4 +172,23 @@ class TestFlattenJson {
             Assert.assertEquals("Separator not applied.", "one", 
parsed["first.second.third.0"])
         }
     }
+
+    @Test
+    void testFlattenSlash() {
+        def testRunner = TestRunners.newTestRunner(FlattenJson.class)
+        def json = prettyPrint(toJson([
+                first: [
+                        second: [
+                                third: [
+                                        "http://localhost/value1";, 
"http://localhost/value2";
+                                ]
+                        ]
+                ]
+        ]))
+
+        testRunner.setProperty(FlattenJson.FLATTEN_MODE, 
FlattenJson.FLATTEN_MODE_NORMAL)
+        baseTest(testRunner, json,2) { parsed ->
+            Assert.assertEquals("Separator not applied.", 
"http://localhost/value1";, parsed["first.second.third[0]"])
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/37ad4884/nifi-nar-bundles/nifi-standard-bundle/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/pom.xml 
b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
index 54fd8f5..7807392 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
@@ -329,7 +329,7 @@
             <dependency>
                 <groupId>com.github.wnameless</groupId>
                 <artifactId>json-flattener</artifactId>
-                <version>0.4.1</version>
+                <version>0.5.0</version>
             </dependency>
             <dependency>
                 <groupId>org.apache.bval</groupId>

Reply via email to