Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013, Francis Galiegue <fgaliegue@gmail.com>
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the Lesser GNU General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * Lesser GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package com.github.fge.jsonschema.main;
 
 
 import static com.github.fge.jsonschema.messages.ConfigurationMessages.*;
 import static com.github.fge.jsonschema.messages.RefProcessingMessages.*;

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.

 
 public final class JsonValidator
 {
     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

Parameters:
schema the schema
instance the instance
Returns:
a validation report
Throws:
com.github.fge.jsonschema.exceptions.ProcessingException an exception occurred during validation
com.github.fge.jsonschema.exceptions.unchecked.ProcessingError the schema or instance is null
 
     public ProcessingReport validate(final JsonNode schema,
         final JsonNode instance)
         throws ProcessingException
     {
         final ProcessingReport report = .newReport();
         final FullData data = buildData(schemainstance);
         return ProcessingResult.of(reportdata).getReport();
     }

    
Validate a schema/instance pair (unchecked mode)

The same warnings as described in JsonSchema.validateUnchecked(com.fasterxml.jackson.databind.JsonNode) apply

Parameters:
schema the schema
instance the instance
Returns:
a validation report
Throws:
com.github.fge.jsonschema.exceptions.unchecked.ProcessingError the schema or instance is null
    public ProcessingReport validateUnchecked(final JsonNode schema,
        final JsonNode instance)
    {
        final ProcessingReport report = .newReport();
        final FullData data = buildData(schemainstance);
        return ProcessingResult.uncheckedResult(reportdata)
            .getReport();
    }

    
Build a JsonSchema instance

Parameters:
schema the schema
pointer the pointer into the schema
Returns:
a new JsonSchema
Throws:
com.github.fge.jsonschema.exceptions.ProcessingException resolving the pointer against the schema leads to a com.fasterxml.jackson.databind.node.MissingNode
com.github.fge.jsonschema.exceptions.unchecked.ProcessingError 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()
                .message());
        return new JsonSchema(tree);
    }

    
Build a JsonSchema instance

Parameters:
uri the URI to load the schema from
Returns:
a JsonSchema
Throws:
com.github.fge.jsonschema.exceptions.ProcessingException invalid URI, or URI did not resolve to a JSON Schema
com.github.fge.jsonschema.exceptions.unchecked.JsonReferenceError URI is null
    JsonSchema buildJsonSchema(final String uri)
        throws ProcessingException
    {
        final JsonRef ref = JsonRef.fromString(uri);
        if (!ref.isLegal())
            throw new JsonReferenceException(new ProcessingMessage()
                .message());
        final SchemaTree tree
            = .get(ref.getLocator()).setPointer(ref.getPointer());
        if (tree.getNode().isMissingNode())
            throw new JsonReferenceException(new ProcessingMessage()
                .message());
        return new JsonSchema(tree);
    }

    
Get the raw processor for this validator (package private)

    {
        return ;
    }
    private FullData buildData(final JsonNode schemafinal JsonNode instance)
    {
        if (schema == null)
            throw new ProcessingError(new ProcessingMessage()
                .message(.));
        if (instance == null)
            throw new ProcessingError(new ProcessingMessage()
                .message());
        final SchemaTree schemaTree = .load(schema);
        final JsonTree tree = new SimpleJsonTree(instance);
        return new FullData(schemaTreetree);
    }
New to GrepCode? Check out our FAQ X