Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com)
   *
   * This software is dual-licensed under:
   *
   * - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
   *   later version;
   * - the Apache Software License (ASL) version 2.0.
   *
  * The text of both licenses is available under the src/resources/ directory of
  * this project (under the names LGPL-3.0.txt and ASL-2.0.txt respectively).
  *
  * Direct link to the sources:
  *
  * - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
  * - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
  */
 
 package com.github.fge.jsonschema.main;
 
 
 import  javax.annotation.concurrent.Immutable;

A generic schema/instance validator

One such instance exists per JsonSchemaFactory. In fact, you have to go through a factory to obtain an instance.

This class is also responsible for building JsonSchema instances.

See also:
JsonSchemaFactory.getValidator()
 
 @Immutable
 public final class JsonValidator
 {
     private static final MessageBundle BUNDLE
         = MessageBundles.getBundle(JsonSchemaCoreMessageBundle.class);
 
     private final SchemaLoader loader;
     private final ValidationProcessor processor;
     private final ReportProvider reportProvider;

    
Package private (and only) constructor

Parameters:
loader the schema loader
processor the validation processor
reportProvider the report provider
 
     JsonValidator(final SchemaLoader loader,
         final ValidationProcessor processor,
         final ReportProvider reportProvider)
     {
         this. = loader;
         this. = processor;
         this. = reportProvider;
     }

    
Validate a schema/instance pair

The third boolean argument instructs the validator as to whether it should validate children even if the container (array or object) fails to validate.

Parameters:
schema the schema
instance the instance
deepCheck see description
Returns:
a validation report
Throws:
ProcessingException an exception occurred during validation
NullPointerException the schema or instance is null
Since:
2.1.8
 
     public ProcessingReport validate(final JsonNode schema,
         final JsonNode instancefinal boolean deepCheck)
         throws ProcessingException
    {
        final ProcessingReport report = .newReport();
        final FullData data = buildData(schemainstancedeepCheck);
        return ProcessingResult.of(reportdata).getReport();
    }


    
Validate a schema/instance pair, "fast" version

This calls validate(JsonNode, JsonNode, boolean) with false as the third argument.

Parameters:
schema the schema
instance the instance
Returns:
a validation report
Throws:
ProcessingException an exception occurred during validation
NullPointerException the schema or instance is null
    public ProcessingReport validate(final JsonNode schema,
        final JsonNode instance)
        throws ProcessingException
    {
        return validate(schemainstancefalse);
    }

    
Validate a schema/instance pair (unchecked mode)

The third boolean argument instructs the validator as to whether it should validate children even if the container (array or object) fails to validate.

The same warnings as described in JsonSchema.validateUnchecked(JsonNode) apply

Parameters:
schema the schema
instance the instance
deepCheck see description
Returns:
a validation report
Throws:
NullPointerException the schema or instance is null
Since:
2.1.8
    public ProcessingReport validateUnchecked(final JsonNode schema,
        final JsonNode instancefinal boolean deepCheck)
    {
        final ProcessingReport report = .newReport();
        final FullData data = buildData(schemainstancedeepCheck);
        return ProcessingResult.uncheckedResult(reportdata)
            .getReport();
    }

    
Validate a schema/instance pair (unchecked mode), "fast" version

This calls validateUnchecked(JsonNode, JsonNode, boolean) with false as a third argument.

The same warnings as described in JsonSchema.validateUnchecked(JsonNode) apply

Parameters:
schema the schema
instance the instance
Returns:
a validation report
Throws:
NullPointerException the schema or instance is null
    public ProcessingReport validateUnchecked(final JsonNode schema,
        final JsonNode instance)
    {
        return validateUnchecked(schemainstancefalse);
    }

    
Build a JsonSchema instance

Parameters:
schema the schema
pointer the pointer into the schema
Returns:
a new JsonSchema
Throws:
ProcessingException resolving the pointer against the schema leads to a MissingNode
NullPointerException the schema or pointer is null
    JsonSchema buildJsonSchema(final JsonNode schemafinal JsonPointer pointer)
        throws ProcessingException
    {
        final SchemaTree tree = .load(schema).setPointer(pointer);
        if (tree.getNode().isMissingNode())
            throw new JsonReferenceException(new ProcessingMessage()
                .setMessage(.getMessage("danglingRef")));
        return new JsonSchema(tree);
    }

    
Build a JsonSchema instance

Parameters:
uri the URI to load the schema from
Returns:
a JsonSchema
Throws:
ProcessingException invalid URI, or URI did not resolve to a JSON Schema
NullPointerException URI is null
    JsonSchema buildJsonSchema(final String uri)
        throws ProcessingException
    {
        final JsonRef ref = JsonRef.fromString(uri);
        if (!ref.isLegal())
            throw new JsonReferenceException(new ProcessingMessage()
                .setMessage(.getMessage("illegalJsonRef")));
        final SchemaTree tree
            = .get(ref.getLocator()).setPointer(ref.getPointer());
        if (tree.getNode().isMissingNode())
            throw new JsonReferenceException(new ProcessingMessage()
                .setMessage(.getMessage("danglingRef")));
        return new JsonSchema(tree);
    }

    
Get the raw processor for this validator (package private)

Returns:
the processor (a ValidationProcessor
    {
        return ;
    }
    private FullData buildData(final JsonNode schemafinal JsonNode instance,
        final boolean deepCheck)
    {
        .checkNotNull(schema"nullSchema");
        .checkNotNull(instance"nullInstance");
        final SchemaTree schemaTree = .load(schema);
        final JsonTree tree = new SimpleJsonTree(instance);
        return new FullData(schemaTreetreedeepCheck);
    }
New to GrepCode? Check out our FAQ X