JsonSchemaValidator { public static boolean isJsonValid(String schemaText, String jsonText) throws IOException { try { List<String> errors = validateJson(schemaText, jsonText); if (!errors.isEmpty()) { log.debug("Get validation errors, returning false"); return false; } } catch (ProcessingException pe) { log.debug("Got processing exception while extracting schema, returning false"); return false; } return true; }  static boolean isJsonValid(String schemaText, String jsonText); static List<String> validateJson(String schemaText, String jsonText); static List<String> validateJson(JsonNode schemaNode, JsonNode jsonNode); static JsonNode getJsonNode(String jsonText); static JsonSchema getSchemaNode(String schemaText); static final String JSON_V4_SCHEMA_IDENTIFIER; static final String JSON_V7_SCHEMA_IDENTIFIER; static final String JSON_SCHEMA_IDENTIFIER_ELEMENT; }
@Test public void testValidateJsonSuccess() { boolean valid = false; String schemaText = null; String jsonText = "{\"name\": \"307\", \"model\": \"Peugeot 307\", \"year\": 2003}"; try { schemaText = FileUtils.readFileToString( new File("target/test-classes/io/github/microcks/util/car-schema.json")); valid = JsonSchemaValidator.isJsonValid(schemaText, jsonText); } catch (Exception e) { fail("Exception should not be thrown"); } assertTrue(valid); }