About Json Schema
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 | 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;
}