1 year ago

#383472

test-img

Amit

How to get custom schema draft in json-schema-validator-1.0.68.jar?

i am defining my custom schema draft in my json-schema.

{   "$schema": "http://oag.company.com/ver1/schema#",   
    "title": "JSON Identity Attribute Schema" 
}

and want to fetch it in code validation. i am using json-schema-validator-1.0.68.jar which comes with com.networknt. my code

public static void main(String[] args) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance();
        String exppath="exp.json";
        String schpath ="schm.json";
        try ( 
                InputStream jsonStream = new FileInputStream(exppath);
                InputStream schemaStream = new FileInputStream(schpath);
        ) {
            JsonNode json = objectMapper.readTree(jsonStream);
            com.networknt.schema.JsonSchema schema = schemaFactory.getSchema(schemaStream);
            Set<ValidationMessage> validationResult = schema.validate(json);
          
            if (validationResult.isEmpty()) {
                
                System.out.println("no validation errors :-)");
                System.out.println(json.path("FirstName"));
            } else {
                validationResult.forEach(vm -> System.out.println(vm));
            }
        }
    }

the error message i got is

Exception in thread "main" com.networknt.schema.JsonSchemaException: Unknown MetaSchema: https://oag.oracle.com/ver1/schema

is thier any way so i can use my custom schema or can i use any other library which allow custom schema ?

java

json

jsonschema

jackson-databind

json-schema-validator

0 Answers

Your Answer

Accepted video resources