com.github.fge.jsonschema.main
Class JsonSchemaFactory

java.lang.Object
  extended by com.github.fge.jsonschema.main.JsonSchemaFactory
All Implemented Interfaces:
Frozen<JsonSchemaFactoryBuilder>

@Immutable
public final class JsonSchemaFactory
extends Object
implements Frozen<JsonSchemaFactoryBuilder>

The main validator provider

From an instance of this factory, you can obtain the following:

See Also:
JsonSchemaFactoryBuilder

Method Summary
static JsonSchemaFactory byDefault()
          Return a default factory
 JsonSchema getJsonSchema(JsonNode schema)
          Build an instance validator tied to a schema
 JsonSchema getJsonSchema(JsonNode schema, String ptr)
          Build an instance validator tied to a subschema from a main schema
 JsonSchema getJsonSchema(String uri)
          Build an instance validator out of a schema loaded from a URI
 Processor<FullData,FullData> getProcessor()
          Return the raw validation processor
 SyntaxValidator getSyntaxValidator()
          Return the syntax validator provided by this factory
 JsonValidator getValidator()
          Return the main schema/instance validator provided by this factory
static JsonSchemaFactoryBuilder newBuilder()
          Return a factory builder
 JsonSchemaFactoryBuilder thaw()
          Return a thawed instance of that factory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

byDefault

public static JsonSchemaFactory byDefault()
Return a default factory

This default factory has validators for both draft v4 and draft v3. It defaults to draft v4.

Returns:
a factory with default settings
See Also:
JsonSchemaFactoryBuilder.JsonSchemaFactoryBuilder()

newBuilder

public static JsonSchemaFactoryBuilder newBuilder()
Return a factory builder

Returns:
a JsonSchemaFactoryBuilder

getValidator

public JsonValidator getValidator()
Return the main schema/instance validator provided by this factory

Returns:
a JsonValidator

getSyntaxValidator

public SyntaxValidator getSyntaxValidator()
Return the syntax validator provided by this factory

Returns:
a SyntaxValidator

getJsonSchema

public JsonSchema getJsonSchema(JsonNode schema)
                         throws ProcessingException
Build an instance validator tied to a schema

Note that the validity of the schema is not checked. Use getSyntaxValidator() if you are not sure.

Parameters:
schema - the schema
Returns:
a JsonSchema
Throws:
ProcessingException - schema is a MissingNode
NullPointerException - schema is null

getJsonSchema

public JsonSchema getJsonSchema(JsonNode schema,
                                String ptr)
                         throws ProcessingException
Build an instance validator tied to a subschema from a main schema

Note that the validity of the schema is not checked. Use getSyntaxValidator() if you are not sure.

Parameters:
schema - the schema
ptr - a JSON Pointer as a string
Returns:
a JsonSchema
Throws:
ProcessingException - ptr is not a valid JSON Pointer, or resolving the pointer against the schema leads to a MissingNode
NullPointerException - schema is null, or pointer is null

getJsonSchema

public JsonSchema getJsonSchema(String uri)
                         throws ProcessingException
Build an instance validator out of a schema loaded from a URI

Parameters:
uri - the URI
Returns:
a JsonSchema
Throws:
ProcessingException - failed to load from this URI
NullPointerException - URI is null

getProcessor

public Processor<FullData,FullData> getProcessor()
Return the raw validation processor

This will allow you to chain the full validation processor with other processors of your choice. Useful if, for instance, you wish to add post checking which JSON Schema cannot do by itself.

Returns:
the processor.

thaw

public JsonSchemaFactoryBuilder thaw()
Return a thawed instance of that factory

Specified by:
thaw in interface Frozen<JsonSchemaFactoryBuilder>
Returns:
a JsonSchemaFactoryBuilder
See Also:
JsonSchemaFactoryBuilder.JsonSchemaFactoryBuilder(JsonSchemaFactory)