All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.everit.json.schema.DefaultValidator Maven / Gradle / Ivy

Go to download

Implementation of the JSON Schema Core Draft v4 - v7 specification built with the org.json API

The newest version!
package org.everit.json.schema;

import org.everit.json.schema.*;

import java.util.function.BiFunction;

class DefaultValidator implements Validator {

    private BiFunction visitorFactory;

    private boolean failEarly;

    private final ReadWriteContext readWriteContext;

    DefaultValidator(boolean failEarly, ReadWriteContext readWriteContext) {
        this.failEarly = failEarly;
        this.readWriteContext = readWriteContext;
    }

    @Override public void performValidation(Schema schema, Object input) {
        ValidationFailureReporter failureReporter = createFailureReporter(schema);
        ReadWriteValidator readWriteValidator = ReadWriteValidators.createForContext(readWriteContext, failureReporter);
        ValidatingVisitor visitor = new ValidatingVisitor(input, failureReporter, readWriteValidator);
        visitor.visit(schema);
        visitor.failIfErrorFound();
    }

    private ValidationFailureReporter createFailureReporter(Schema schema) {
        if (failEarly) {
            return new EarlyFailingFailureReporter(schema);
        }
        return new CollectingFailureReporter(schema);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy