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:
Mark Payne 2018-11-07 09:08:54 -05:00 committed by Pierre Villard
parent 13232c7413
commit 3ba0c0ca82
2 changed files with 13 additions and 1 deletions

View File

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

View File

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