NIFI-4962 FlattenJson processor add unexpected backslash after flatten

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

This closes #2538.
This commit is contained in:
Deon Huang 2018-03-14 00:04:29 +08:00 committed by Pierre Villard
parent 11a7d5c09f
commit 37ad48844a
3 changed files with 22 additions and 1 deletions

View File

@ -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()));

View File

@ -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]"])
}
}
}

View File

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