public ProcessingReport validate(String jsonText) throws IOException { ProcessingReport report; JsonNode toValidate = JsonLoader.fromString(jsonText); try { report = this.schema.validate(toValidate); } catch (ProcessingException e) { throw new IOException("Error validating json text : " + e.getMessage()); } return report; } }
private final ValidationResult getValidationResult(JsonNode jsonNode) throws IOException { try { ProcessingReport processingReport = schema.validate(jsonNode); if (processingReport != null) { return new ValidationResult(processingReport.isSuccess(), processingReport.toString()); } else { return new ValidationResult(false, null); } } catch (ProcessingException e) { throw new IOException(e.getMessage()); } }
@Test public void processingExceptionMessageIsSameAsProcessingMessage() { final ProcessingMessage message = new ProcessingMessage() .setMessage(FOO); final ProcessingException exception = new ProcessingException(message); assertEquals(exception.getMessage(), message.toString()); }
public final void validate(final MessageBuilder builder, final JsonNode input) { final ProcessingReport report; try { report = validator.validate(input); if (!fillMessages(report, builder)) { builder.append(new Message("", "JSON Schema validation failed", Severity.ERROR)); } } catch (ProcessingException e) { builder.append(new Message("", e.getMessage(), Severity.ERROR)); } }
@Override public void validate(Reader content, Reader schema, RamlViolations violations, Message message) { init(); try (final Reader s = schema) { final JsonSchema jsonSchema = factory.getJsonSchema(JsonLoader.fromReader(schema)); final ProcessingReport report = jsonSchema.validate(JsonLoader.fromReader(content)); if (!report.isSuccess()) { String msg = ""; for (final ProcessingMessage reportLine : report) { msg += new Message("jsonSchemaValidator.message", reportLine.toString()); } violations.add(message.withParam(msg), new JsonSchemaViolationCause(report)); } } catch (ProcessingException e) { violations.add(message.withMessageParam("schema.invalid", e.getMessage()), new JsonSchemaViolationCause(e)); } catch (IOException e) { violations.add(message.withMessageParam("schema.invalid", e.getMessage())); } } }
@Override public void validate(Reader content, Reader schema, RamlViolations violations, Message message) { init(); try (final Reader s = schema) { final JsonSchemaFactory factory = this.factory == null ? JsonSchemaFactory.byDefault() : this.factory; final JsonSchema jsonSchema = factory.getJsonSchema(JsonLoader.fromReader(schema)); final ProcessingReport report = jsonSchema.validate(JsonLoader.fromReader(content)); if (!report.isSuccess()) { String msg = ""; for (final ProcessingMessage reportLine : report) { msg += new Message("jsonSchemaValidator.message", reportLine.toString()); } violations.add(message.withParam(msg), new JsonSchemaViolationCause(report)); } } catch (ProcessingException e) { violations.add(message.withMessageParam("schema.invalid", e.getMessage()), new JsonSchemaViolationCause(e)); } catch (IOException e) { violations.add(message.withMessageParam("schema.invalid", e.getMessage())); } } }