Wren Security Commons JSON Schema - Draft-04 Validator 23.0.0-SNAPSHOT Documentation

The JSON Schema Validator is a tool to validates simple java object against the draft-fge-json-schema-validation-00 schema.

The instance object is a simple Java object.

JSON type to Java type mapping
JSON Java
string java.lang.String
number java.lang.Number
true|false java.lang.Boolean
null null
array java.util.List
object java.util.Map

The schema MUST be a Map<String, Object>.

Simple example of how to use the sample implementation:

Map<String, Object> schema = {initialize the schema};
Object instance = {the instance to validate};

if (ObjectValidator.validate(instance, schema)) {
//Object is valid
} else {
//object violates the schema
}

Use this tool to integrate it to custom environment and optimise the reuse of the validators. It was designed to be thread safe an single instance of the Validators can be reused.

More advanced sample:

Map<String, Object> schema = {initialize the schema};
Object instance = {the instance to validate};

try {
Validator v = ObjectValidatorFactory.getTypeValidator(schema);
ErrorHandler handler = new FailFastErrorHandler();
v.validate(instance, null, handler);
} catch (Throwable e) {
isValid = false;
}

 

Packages
Package
Description
These classes are the commonly used classes from other applications.
Schema validator exceptions.
These classes are capable of helping the validators to check certain constraints.
These classes are capable of validating the objects against the initially loaded schema.