mirror of https://github.com/apache/nifi.git
[NIFI-11509] Added configuration to allow for parsing comments in JSON.
This closes #7220 Signed-off-by: Mike Thomsen <mthomsen@apache.org>
This commit is contained in:
parent
71c7d38c75
commit
e4cdb90a75
|
@ -722,6 +722,7 @@
|
||||||
<exclude>src/test/resources/TestValidateJson/schema-simple-example-unmatched-pattern.json</exclude>
|
<exclude>src/test/resources/TestValidateJson/schema-simple-example-unmatched-pattern.json</exclude>
|
||||||
<exclude>src/test/resources/TestValidateJson/schema-simple-example.json</exclude>
|
<exclude>src/test/resources/TestValidateJson/schema-simple-example.json</exclude>
|
||||||
<exclude>src/test/resources/TestValidateJson/simple-example.json</exclude>
|
<exclude>src/test/resources/TestValidateJson/simple-example.json</exclude>
|
||||||
|
<exclude>src/test/resources/TestValidateJson/simple-example-with-comments.json</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.processors.standard;
|
package org.apache.nifi.processors.standard;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.networknt.schema.JsonSchema;
|
import com.networknt.schema.JsonSchema;
|
||||||
|
@ -151,7 +152,11 @@ public class ValidateJson extends AbstractProcessor {
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
private static final ObjectMapper MAPPER;
|
||||||
|
static {
|
||||||
|
MAPPER = new ObjectMapper();
|
||||||
|
MAPPER.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
|
||||||
|
}
|
||||||
|
|
||||||
private JsonSchema schema;
|
private JsonSchema schema;
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,22 @@ class TestValidateJson {
|
||||||
assertThrows(AssertionFailedError.class, () -> runner.run());
|
assertThrows(AssertionFailedError.class, () -> runner.run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testJsonWithComments() {
|
||||||
|
final String schemaPath = getFilePath("schema-simple-example.json");
|
||||||
|
runner.setProperty(ValidateJson.SCHEMA_CONTENT, schemaPath);
|
||||||
|
runner.setProperty(ValidateJson.SCHEMA_VERSION, SCHEMA_VERSION);
|
||||||
|
|
||||||
|
runner.enqueue(getFileContent("simple-example-with-comments.json"));
|
||||||
|
|
||||||
|
runner.run();
|
||||||
|
|
||||||
|
runner.assertTransferCount(ValidateJson.REL_FAILURE, 0);
|
||||||
|
runner.assertTransferCount(ValidateJson.REL_INVALID, 0);
|
||||||
|
runner.assertTransferCount(ValidateJson.REL_VALID, 1);
|
||||||
|
|
||||||
|
assertValidationErrors(ValidateJson.REL_VALID, false);
|
||||||
|
}
|
||||||
private void assertValidationErrors(Relationship relationship, boolean expected) {
|
private void assertValidationErrors(Relationship relationship, boolean expected) {
|
||||||
final Map<String, String> attributes = runner.getFlowFilesForRelationship(relationship).get(0).getAttributes();
|
final Map<String, String> attributes = runner.getFlowFilesForRelationship(relationship).get(0).getAttributes();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
//First comment
|
||||||
|
"FieldOne": "stringValue",
|
||||||
|
/*Second comment*/
|
||||||
|
"FieldTwo": 1234,
|
||||||
|
//Third comment
|
||||||
|
"FieldThree": [
|
||||||
|
{
|
||||||
|
"arrayField": "arrayValue"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue