public List<String> returnJSONObjects(String jsonArray) { List<String> arrayItems = new ArrayList<String>(); try { JsonNode jsonNode = objectMapper.readTree(jsonArray); if (jsonNode instanceof ArrayNode) { for (JsonNode arrayElement : jsonNode) { arrayItems.add(JacksonUtils.prettyPrint(arrayElement)); } } else { arrayItems.add(JacksonUtils.prettyPrint(jsonNode)); } } catch (IOException e) { throw new IllegalArgumentException(e); } return arrayItems; }
@Override public RetCode validateInstance(final JsonSchema schema, final String fileName, final JsonNode node) throws IOException, ProcessingException { final ListProcessingReport report = (ListProcessingReport) schema.validate(node, true); final boolean success = report.isSuccess(); System.out.println("--- BEGIN " + fileName + "---"); System.out.println("validation: " + (success ? "SUCCESS" : "FAILURE")); if (!success) System.out.println(JacksonUtils.prettyPrint(report .asJson())); System.out.println("--- END " + fileName + "---"); return success ? ALL_OK : VALIDATION_FAILURE; } },
@Override public RetCode validateSchema(final SyntaxValidator validator, final String fileName, final JsonNode node) throws IOException { final ListProcessingReport report = (ListProcessingReport) validator.validateSchema(node); final boolean success = report.isSuccess(); System.out.println("--- BEGIN " + fileName + "---"); System.out.println("validation: " + (success ? "SUCCESS" : "FAILURE")); if (!success) System.out.println(JacksonUtils.prettyPrint(report.asJson())); System.out.println("--- END " + fileName + "---"); return success ? ALL_OK : SCHEMA_SYNTAX_ERROR; }
private ProcessingMessage collectSyntaxErrors(final ProcessingReport report) { /* * OK, that's for issue #99 but that's ugly nevertheless. * * We want syntax error messages to appear in the exception text. */ final String msg = syntaxMessages.getMessage("core.invalidSchema"); final ArrayNode arrayNode = JacksonUtils.nodeFactory().arrayNode(); JsonNode node; for (final ProcessingMessage message: report) { node = message.asJson(); if ("syntax".equals(node.path("domain").asText())) arrayNode.add(node); } final StringBuilder sb = new StringBuilder(msg); sb.append("\nSyntax errors:\n"); sb.append(JacksonUtils.prettyPrint(arrayNode)); return new ProcessingMessage().setMessage(sb.toString()); } }
public List<String> returnJSONObjects(String jsonArray) { List<String> arrayItems = new ArrayList<String>(); try { JsonNode jsonNode = objectMapper.readTree(jsonArray); if (jsonNode instanceof ArrayNode) { for (JsonNode arrayElement : jsonNode) { arrayItems.add(JacksonUtils.prettyPrint(arrayElement)); } } else { arrayItems.add(JacksonUtils.prettyPrint(jsonNode)); } } catch (IOException e) { throw new IllegalArgumentException(e); } return arrayItems; }
private static boolean fillMessages(final ProcessingReport report, final MessageBuilder builder) { final Severity severity = LEVEL_MAP.get(report.getLogLevel()); final ArrayNode node = JacksonUtils.nodeFactory().arrayNode(); for (final ProcessingMessage processingMessage : report) { node.add(processingMessage.asJson()); } final String reportAsString = JacksonUtils.prettyPrint(node); final Message message = new Message("", reportAsString, severity); builder.append(message); return report.isSuccess(); }
@Test(dataProvider = "validationPairProvider") public void validateTestData(SchemaFile schemaFile, DataFile dataFile) throws Exception { ProcessingReport report = schemaFile.getJsonSchema().validate(dataFile.getData()); DataFileValidationResult validationResult = report.isSuccess() ? PASS : FAIL; if (validationResult != dataFile.getExpectedValidationResult()) { for (ProcessingMessage processingMessage : report) { logger.error(JacksonUtils.prettyPrint(processingMessage.asJson())); } } assertThat(dataFile.getExpectedValidationResult(), equalTo(validationResult)); }
for (ProcessingMessage processingMessage : report) { if (processingMessage.getLogLevel() != LogLevel.WARNING) { log.error(JacksonUtils.prettyPrint(processingMessage.asJson())); for (ProcessingMessage processingMessage : report) { if (processingMessage.getLogLevel() != LogLevel.WARNING) { log.error(JacksonUtils.prettyPrint(processingMessage.asJson()));