mirror of
https://github.com/apache/nifi.git
synced 2025-02-07 18:48:51 +00:00
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:
parent
11a7d5c09f
commit
37ad48844a
@ -20,6 +20,7 @@ package org.apache.nifi.processors.standard;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.wnameless.json.flattener.FlattenMode;
|
import com.github.wnameless.json.flattener.FlattenMode;
|
||||||
import com.github.wnameless.json.flattener.JsonFlattener;
|
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.behavior.SideEffectFree;
|
||||||
import org.apache.nifi.annotation.documentation.CapabilityDescription;
|
import org.apache.nifi.annotation.documentation.CapabilityDescription;
|
||||||
import org.apache.nifi.annotation.documentation.Tags;
|
import org.apache.nifi.annotation.documentation.Tags;
|
||||||
@ -160,6 +161,7 @@ public class FlattenJson extends AbstractProcessor {
|
|||||||
final String flattened = new JsonFlattener(raw)
|
final String flattened = new JsonFlattener(raw)
|
||||||
.withFlattenMode(flattenMode)
|
.withFlattenMode(flattenMode)
|
||||||
.withSeparator(separator.charAt(0))
|
.withSeparator(separator.charAt(0))
|
||||||
|
.withStringEscapePolicy(() -> StringEscapeUtils.ESCAPE_JAVA)
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
||||||
flowFile = session.write(flowFile, os -> os.write(flattened.getBytes()));
|
flowFile = session.write(flowFile, os -> os.write(flattened.getBytes()));
|
||||||
|
@ -172,4 +172,23 @@ class TestFlattenJson {
|
|||||||
Assert.assertEquals("Separator not applied.", "one", parsed["first.second.third.0"])
|
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]"])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.wnameless</groupId>
|
<groupId>com.github.wnameless</groupId>
|
||||||
<artifactId>json-flattener</artifactId>
|
<artifactId>json-flattener</artifactId>
|
||||||
<version>0.4.1</version>
|
<version>0.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.bval</groupId>
|
<groupId>org.apache.bval</groupId>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user