@Override public void mergeWith(final ProcessingReport processingReport) { success = success || processingReport.isSuccess(); processingReport.forEach(messages::add); }
/** * Constructs the error message of a failed validation based on the processing report passed from * com.github.fge.jsonschema.core.report * @param report The report containing the error message * @return A string representation of all messages contained in the report */ private String constructErrorMessage(ProcessingReport report) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Json validation failed: "); report.forEach(processingMessage -> stringBuilder.append(processingMessage.getMessage())); return stringBuilder.toString(); }
private void validateWithSchema(JsonNode model) { createValidator(); try { ProcessingReport report = validator.validate(model); if (report != null) { List<String> msgs = Lists.newArrayList(); report.forEach(msg -> { if (msg.getLogLevel().compareTo(LogLevel.ERROR) >= 0) { String ptr = msg.asJson().at("/instance/pointer").asText(); msgs.add(String.format("At %s: %s", ptr.isEmpty() ? "/" : ptr, msg.getMessage())); } }); if (!msgs.isEmpty()) { throw new RealizationModelParseException(msgs); } } } catch (ProcessingException e) { e.printStackTrace(); } }
private static void validate(CanonicalPath dataPath, JsonNode dataNode, JsonNode schemaNode) { //explicitly allow null schemas if (dataNode == null || dataNode.isNull()) { return; } try { ProcessingReport report = VALIDATOR.validate(schemaNode, dataNode, true); if (!report.isSuccess()) { List<ValidationMessage> messages = new ArrayList<>(); report.forEach((m) -> messages.add(new ValidationMessage(m.getLogLevel().name(), m.toString()))); throw new ValidationException(dataPath, messages, null); } } catch (ProcessingException e) { throw new ValidationException(dataPath, emptyList(), e); } }