use of com.github.fge.jsonschema.core.report.ProcessingReport in project useful-java-links by Vedenin.
the class JsonSchemaValidatorHelloWorld method main.
public static void main(final String... args) throws IOException, ProcessingException {
final JsonNode fstabSchema = Utils.loadResource("/fstab.json");
final JsonNode good = Utils.loadResource("/fstab-good.json");
final JsonNode bad = Utils.loadResource("/fstab-bad.json");
final JsonNode bad2 = Utils.loadResource("/fstab-bad2.json");
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(fstabSchema);
ProcessingReport report;
report = schema.validate(good);
System.out.println(report);
report = schema.validate(bad);
System.out.println(report);
report = schema.validate(bad2);
System.out.println(report);
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project metron by apache.
the class AbstractParserConfigTest method validateJsonData.
protected boolean validateJsonData(final String jsonSchema, final String jsonData) throws IOException, ProcessingException {
final JsonNode d = JsonLoader.fromString(jsonData);
final JsonNode s = JsonLoader.fromString(jsonSchema);
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonValidator v = factory.getValidator();
ProcessingReport report = v.validate(s, d);
return report.toString().contains("success");
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project metron by apache.
the class CEFParserTest method validateJsonData.
protected boolean validateJsonData(final String jsonSchema, final String jsonData) throws Exception {
final JsonNode d = JsonLoader.fromString(jsonData);
final JsonNode s = JsonLoader.fromString(jsonSchema);
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonValidator v = factory.getValidator();
ProcessingReport report = v.validate(s, d);
return report.toString().contains("success");
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project oc-explorer by devgateway.
the class OcdsSchemaValidatorService method validate.
/**
* Validates the incoming {@link JsonNode} against OCDS schema
*
* @param jsonNode
* @return
*/
public ProcessingReportWithNode validate(final JsonNode jsonNode) {
try {
ProcessingReport processingReport = schema.validate(jsonNode);
ProcessingReportWithNode processingReportWithNode = null;
try {
processingReportWithNode = new ProcessingReportWithNode(processingReport, processingReport.isSuccess() ? null : jacksonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode));
} catch (JsonProcessingException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
return processingReportWithNode;
} catch (ProcessingException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
return null;
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method schemaMatch.
/**
* Check if response matches schema
*
* @param p Path to the schema to be tested
* @return TestItemReport
*/
private TestExecReport schemaMatch(String p) {
LOGGER.info("Testing Schema");
TestExecReport tr = new TestExecReport("Json matches schema: " + p, false);
tr.setType("schema mismatch");
tr.setSchema(p);
try {
String jsonString = vr.extract().response().asString();
SchemaValidator schemaValidator = new SchemaValidator();
ProcessingReport r = schemaValidator.validate(p, jsonString);
if (r.isSuccess()) {
LOGGER.info("Schema Test Passed");
tr.addMessage("Response structure matches schema.");
tr.setPassed(true);
} else {
LOGGER.info("Schema Test Failed");
tr.addMessage("Response structure doesn't match schema.");
r.forEach(message -> tr.addError(message.asJson()));
}
return tr;
} catch (ConnectionClosedException | JsonParseException e1) {
LOGGER.info("Invalid response");
LOGGER.info("== cause ==");
LOGGER.info(e1.getMessage());
tr.addMessage("Server response is not valid JSON.");
return tr;
} catch (AssertionError | IOException | ProcessingException e1) {
LOGGER.info("Doesn't match schema");
LOGGER.info("== cause ==");
LOGGER.info(e1.getMessage());
tr.addMessage(e1.getMessage());
return tr;
}
}
Aggregations