use of com.networknt.schema.ValidationMessage in project light-rest-4j by networknt.
the class SchemaValidator method doValidate.
private Status doValidate(final Object value, final Object schema) {
requireNonNull(schema, "A schema is required");
Status status = null;
Set<ValidationMessage> processingReport = null;
try {
final JsonNode schemaObject = Json.mapper().readTree(Json.pretty(schema));
if (api != null) {
if (this.definitions == null) {
this.definitions = Json.mapper().readTree(Json.pretty(api.getDefinitions()));
}
((ObjectNode) schemaObject).set(DEFINITIONS_FIELD, this.definitions);
}
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schemaObject);
final JsonNode content = Json.mapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
} catch (JsonParseException e) {
return new Status(VALIDATOR_SCHEMA_INVALID_JSON, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
if (processingReport != null && processingReport.size() > 0) {
ValidationMessage vm = processingReport.iterator().next();
status = new Status(VALIDATOR_SCHEMA, vm.getMessage());
}
return status;
}
Aggregations