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;
 
Single-schema instance validator

This is the class you will use the most often. It is, in essence, a JsonValidator initialized with a single JSON Schema. Note however that this class still retains the ability to resolve JSON References.

It has no public constructors: you should use the appropriate methods in JsonSchemaFactory to obtain an instance of this class.

 
 public final class JsonSchema
 {
     private final ValidationProcessor processor;
     private final SchemaTree schema;
     private final ReportProvider reportProvider;

    
Package private constructor

Parameters:
processor the validation processor
schema the schema to bind to this instance
reportProvider the report provider
 
     JsonSchema(final ValidationProcessor processorfinal SchemaTree schema,
         final ReportProvider reportProvider)
     {
         this. = processor;
         this. = schema;
         this. = reportProvider;
     }
 
     private ProcessingReport doValidate(final JsonNode node)
         throws ProcessingException
     {
         final FullData data = new FullData(new SimpleJsonTree(node));
         final ProcessingReport report = .newReport();
         final ProcessingResult<FullDataresult
             =  ProcessingResult.of(reportdata);
         return result.getReport();
     }
 
     private ProcessingReport doValidateUnchecked(final JsonNode node)
     {
         final FullData data = new FullData(new SimpleJsonTree(node));
         final ProcessingReport report = .newReport();
         final ProcessingResult<FullDataresult
             =  ProcessingResult.uncheckedResult(reportdata);
         return result.getReport();
     }

    
Validate an instance and return a processing report

Parameters:
instance the instance to validate
Returns:
a processing report
Throws:
com.github.fge.jsonschema.exceptions.ProcessingException a processing error occurred during validation
 
     public ProcessingReport validate(final JsonNode instance)
         throws ProcessingException
     {
         return doValidate(instance);
     }

    
Validate an instance and return a processing report (unchecked version)

Unchecked validation means that conditions which would normally cause the processing to stop with an exception are instead inserted into the resulting report.

Warning: this means that anomalous events like an unresolvable JSON Reference, or an invalid schema, are masked!

Parameters:
instance the instance to validate
Returns:
a report (a com.github.fge.jsonschema.report.ListProcessingReport if an exception was thrown during processing)
    public ProcessingReport validateUnchecked(final JsonNode instance)
    {
        return doValidateUnchecked(instance);
    }

    
Check whether an instance is valid against this schema

Parameters:
instance the instance
Returns:
true if the instance is valid
Throws:
com.github.fge.jsonschema.exceptions.ProcessingException an error occurred during processing
    public boolean validInstance(final JsonNode instance)
        throws ProcessingException
    {
        return doValidate(instance).isSuccess();
    }

    
Check whether an instance is valid against this schema (unchecked version)

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

Parameters:
instance the instance to validate
Returns:
true if the instance is valid
    public boolean validInstanceUnchecked(final JsonNode instance)
    {
        return doValidateUnchecked(instance).isSuccess();
    }
New to GrepCode? Check out our FAQ X