mirror of https://github.com/apache/nifi.git
NIFI-487: Changing the default JSON provider from SmartJson to Jackson to address issues with control characters causing documents to not get parsed correctly.
This commit is contained in:
parent
081994e119
commit
3295f7f193
|
@ -172,6 +172,11 @@
|
|||
<artifactId>tika-core</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.4.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -195,6 +200,7 @@
|
|||
<exclude>src/test/resources/TestEncryptContent/text.txt.asc</exclude>
|
||||
<exclude>src/test/resources/TestIdentifyMimeType/1.txt</exclude>
|
||||
<exclude>src/test/resources/TestJson/json-sample.json</exclude>
|
||||
<exclude>src/test/resources/TestJson/control-characters.json</exclude>
|
||||
<exclude>src/test/resources/TestMergeContent/demarcate</exclude>
|
||||
<exclude>src/test/resources/TestMergeContent/foot</exclude>
|
||||
<exclude>src/test/resources/TestMergeContent/head</exclude>
|
||||
|
|
|
@ -19,9 +19,8 @@ package org.apache.nifi.processors.standard;
|
|||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
|
||||
import com.jayway.jsonpath.spi.json.JsonProvider;
|
||||
import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider;
|
||||
import net.minidev.json.parser.JSONParser;
|
||||
import org.apache.nifi.components.PropertyDescriptor;
|
||||
import org.apache.nifi.components.ValidationContext;
|
||||
import org.apache.nifi.components.ValidationResult;
|
||||
|
@ -50,7 +49,7 @@ import java.util.Objects;
|
|||
*/
|
||||
public abstract class AbstractJsonPathProcessor extends AbstractProcessor {
|
||||
|
||||
private static final Configuration STRICT_PROVIDER_CONFIGURATION = Configuration.builder().jsonProvider(new JsonSmartJsonProvider(JSONParser.MODE_RFC4627)).build();
|
||||
private static final Configuration STRICT_PROVIDER_CONFIGURATION = Configuration.builder().jsonProvider(new JacksonJsonProvider()).build();
|
||||
|
||||
private static final JsonProvider JSON_PROVIDER = STRICT_PROVIDER_CONFIGURATION.jsonProvider();
|
||||
|
||||
|
|
|
@ -344,4 +344,23 @@ public class TestEvaluateJsonPath {
|
|||
assertEquals("Null Value", "null", nullValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleAsciiControlCharacters() throws Exception {
|
||||
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
|
||||
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);
|
||||
testRunner.setProperty(EvaluateJsonPath.RETURN_TYPE, EvaluateJsonPath.RETURN_TYPE_JSON);
|
||||
|
||||
final String jsonPathControlCharKey = "evaluatejson.controlcharacterpath";
|
||||
|
||||
testRunner.setProperty(jsonPathControlCharKey, "$.jinxing_json.object.property");
|
||||
|
||||
testRunner.enqueue(Paths.get("src/test/resources/TestJson/control-characters.json"));
|
||||
testRunner.run();
|
||||
|
||||
final Relationship expectedRel = EvaluateJsonPath.REL_MATCH;
|
||||
|
||||
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
|
||||
final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
|
||||
Assert.assertNotNull("Transferred flow file did not have the correct result for id attribute", out.getAttribute(jsonPathControlCharKey));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"jinxing_json": {
|
||||
"object": {
|
||||
"property": "Arbitrary characters to the right more normal characters"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue