mirror of https://github.com/apache/nifi.git
NIFI-5798: Fixed bug in FlattenJson that was escaping text as Java instead of escaping as JSON
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #3138.
This commit is contained in:
parent
13232c7413
commit
3ba0c0ca82
|
@ -162,7 +162,7 @@ public class FlattenJson extends AbstractProcessor {
|
|||
final String flattened = new JsonFlattener(raw)
|
||||
.withFlattenMode(flattenMode)
|
||||
.withSeparator(separator.charAt(0))
|
||||
.withStringEscapePolicy(() -> StringEscapeUtils.ESCAPE_JAVA)
|
||||
.withStringEscapePolicy(() -> StringEscapeUtils.ESCAPE_JSON)
|
||||
.flatten();
|
||||
|
||||
flowFile = session.write(flowFile, os -> os.write(flattened.getBytes()));
|
||||
|
|
|
@ -191,4 +191,16 @@ class TestFlattenJson {
|
|||
Assert.assertEquals("Separator not applied.", "http://localhost/value1", parsed["first.second.third[0]"])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEscapeForJson() {
|
||||
def testRunner = TestRunners.newTestRunner(FlattenJson.class)
|
||||
def json = prettyPrint(toJson([ name: "José"
|
||||
]))
|
||||
|
||||
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_NORMAL)
|
||||
baseTest(testRunner, json,1) { parsed ->
|
||||
Assert.assertEquals("Separator not applied.", "José", parsed["name"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue