Json-Schema-Validator library:

669 views Asked by At

I'm using the library https://github.com/daveclayton/json-schema-validator (@daveclayton) to validate my generated json against jsonschema.

private static boolean validateTestdataAgainstSchema(String testdata) throws IOException{
    try{
         ObjectMapper mapper = new ObjectMapper();
         SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
         mapper.acceptJsonFormatVisitor(Configuration.getBaseBeanClass(), visitor);
         JsonSchema schema = visitor.finalSchema();
         FileSystem.writeToFile("schema.json",mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema));
         final File jsonSchemaFile = new File("schema.json");
         final URI uri = jsonSchemaFile.toURI();   

       JsonNode data = JsonLoader.fromString(testdata);

       JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
       com.github.fge.jsonschema.main.JsonSchema schemaa = factory.getJsonSchema(uri.toString());
       ProcessingReport report = schemaa.validate(data);
       return report.isSuccess();
    }catch(Exception ex){
        ex.printStackTrace();
    }
    return false;
}

I get the below exception on validation. Could anyone please help

com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: URI scheme "urn" not supported (URI: "urn:jsonschema:au:com:superchoice:services:enterprise:domain:i6:amount:NonNegativeAmount#")
level: "fatal"
scheme: "urn"
uri: "urn:jsonschema:au:com:superchoice:services:enterprise:domain:i6:amount:NonNegativeAmount#"

JSONSchema

JSONData

0

There are 0 answers