Package uk.co.o2.json.schema

Examples of uk.co.o2.json.schema.JsonSchema.validate()


    @Test
    public void validateSchema_shouldWorkFromADifferentPackage() throws Exception {
        JsonSchema schema = schemaFactory.getSchema(getClass().getClassLoader().getResource("sample-json-schema.json"));
        JsonNode json = jsonFactory.createJsonParser(getClass().getClassLoader().getResource("valid-json-document.json")).readValueAsTree();

        List<ErrorMessage> errors = schema.validate(json);

        assertTrue(errors.isEmpty());
    }

}
View Full Code Here


            JsonParser jp = mapper.getFactory().createJsonParser(entityStream);
            jp.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
            URL schemaLocation = schemaLookup.getSchemaURL(schemaAnnotation.value());
            JsonSchema jsonSchema = cache.getSchema(schemaLocation);
            JsonNode jsonNode = mapper.readTree(jp);
            List<ErrorMessage> validationErrors = jsonSchema.validate(jsonNode);
            if (validationErrors.isEmpty()) {
                return mapper.reader().withType(mapper.constructType(genericType)).readValue(jsonNode);
            }

            throw new WebApplicationException(generateErrorMessage(validationErrors));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.