-
- All Known Subinterfaces:
ObjectJsonSchema
public interface JsonSchemaAn immutable JSON schema.A JSON schema can be read from
InputStreamorReader. The following example shows how to read a JSON schema from aStringReader:JsonValidationService service = JsonValidationService.newInstance(); StringReader reader = new StringReader("{\"type\": \"integer\"}"); JsonSchema schema = service.readSchema(reader);Alternatively, a JSON schema can be built programmatically with
JsonSchemaBuilderas follows.JsonSchemaBuilderFactory factory = service.createSchemaBuilderFactory(); JsonSchemaBuilder builder = factory.createBuilder(); JsonSchema schema = builder.withType(InstanceType.INTEGER).build();All instances of this type except
TRUEandFALSEcan be casted toObjectJsonSchema.Any instance of this class is safe for use by multiple concurrent threads after schema reading or schema building once completed.
- Author:
- leadpony
-
-
Field Summary
Fields Modifier and Type Field Description static ObjectJsonSchemaEMPTYThe JSON schema represented by an empty JSON object.static JsonSchemaFALSEThe JSON schema which is always evaluated as false.static JsonSchemaTRUEThe JSON schema which is always evaluated as true.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ObjectJsonSchemaasObjectJsonSchema()Returns this JSON schema as aObjectJsonSchema.default Stringcomment()Returns the comment for this schema, which is supplied by "$comment" keyword.default booleancontainsKeyword(String keyword)Checks if this schema contains the specified keyword or not.EvaluatorcreateEvaluator(EvaluatorContext context, InstanceType type)Creates an evaluator of this schema.EvaluatorcreateNegatedEvaluator(EvaluatorContext context, InstanceType type)Creates an evaluator of the negated version of this schema.default JsonValuedefaultValue()Returns the default value of this schema, which is supplied by "default" keyword.default Stringdescription()Returns the description of this schema, which is supplied by "description" keyword.default Stream<JsonSchema>getInPlaceSubschemas()Returns all of the subschemas of this schema which will be applied to the same instance location as this one.JsonValue.ValueTypegetJsonValueType()Returns the value type of JSON representing this schema.default JsonValuegetKeywordValue(String keyword)Returns the value of the specified schema keyword as aJsonValue.default JsonValuegetKeywordValue(String keyword, JsonValue defaultValue)Returns the value of the specified schema keyword as aJsonValue.default JsonSchemagetSubschemaAt(String jsonPointer)Returns the subschema at the location specified with a JSON pointer.default Stream<JsonSchema>getSubschemas()Returns all of the subschemas contained in this schema.default booleanhasAbsoluteId()Checks if this schema has an identifier and the identifier is absolute.default booleanhasId()Checks if this schema has an identifier assigned or not.default URIid()Returns the identifier of this schema, which is supplied by "$id" keyword.booleanisBoolean()Checks if this schema is a boolean schema.default URIschema()Returns the version identifier of this schema, which is supplied by "$schema" keyword.default Stringtitle()Returns the title of this schema, which is supplied by "title" keyword.JsonValuetoJson()Returns the JSON representation of this schema.StringtoString()Returns the string representation of this schema.static JsonSchemavalueOf(boolean value)Returns a boolean schema instance representing the specified boolean value.
-
-
-
Field Detail
-
TRUE
static final JsonSchema TRUE
The JSON schema which is always evaluated as true. Any JSON instance satisfy this schema.
-
FALSE
static final JsonSchema FALSE
The JSON schema which is always evaluated as false. Any JSON instance does not satisfy this schema.
-
EMPTY
static final ObjectJsonSchema EMPTY
The JSON schema represented by an empty JSON object. This schema is always evaluated as true.
-
-
Method Detail
-
hasId
default boolean hasId()
Checks if this schema has an identifier assigned or not.- Returns:
trueif this schema has an identifier.falseif this schema does not have an identifier.
-
hasAbsoluteId
default boolean hasAbsoluteId()
Checks if this schema has an identifier and the identifier is absolute.- Returns:
trueif this schema has an absolute identifier.falseif this schema does not have an absolute identifier.- See Also:
hasId()
-
id
default URI id()
Returns the identifier of this schema, which is supplied by "$id" keyword.- Returns:
- the identifier of this schema, or
nullif not exists.
-
schema
default URI schema()
Returns the version identifier of this schema, which is supplied by "$schema" keyword.- Returns:
- the version identifier of this schema, or
nullif not exists.
-
comment
default String comment()
Returns the comment for this schema, which is supplied by "$comment" keyword.- Returns:
- the comment for this schema, or
nullif not exists.
-
title
default String title()
Returns the title of this schema, which is supplied by "title" keyword.- Returns:
- the title of this schema, or
nullif not exists.
-
description
default String description()
Returns the description of this schema, which is supplied by "description" keyword.- Returns:
- the description of this schema, or
nullif not exists.
-
defaultValue
default JsonValue defaultValue()
Returns the default value of this schema, which is supplied by "default" keyword.- Returns:
- the default value of this schema. or
nullif not exists.
-
isBoolean
boolean isBoolean()
Checks if this schema is a boolean schema.- Returns:
trueif this schema is a boolean schema,falseotherwise.
-
asObjectJsonSchema
default ObjectJsonSchema asObjectJsonSchema()
Returns this JSON schema as aObjectJsonSchema.- Returns:
- the instance of
ObjectJsonSchema. - Throws:
ClassCastException- if this instance is not aObjectJsonSchema.
-
containsKeyword
default boolean containsKeyword(String keyword)
Checks if this schema contains the specified keyword or not.- Parameters:
keyword- the name of the keyword.- Returns:
trueif this schema contains the specified keyword,falseotherwise.- Throws:
NullPointerException- if the specifiedkeywordisnull.
-
getKeywordValue
default JsonValue getKeywordValue(String keyword)
Returns the value of the specified schema keyword as aJsonValue.- Parameters:
keyword- the name of the schema keyword, such as"type".- Returns:
- keyword value if this schema contains the keyword, or
nullif this schema does not contain the keyword. - Throws:
NullPointerException- if the specifiedkeywordisnull.
-
getKeywordValue
default JsonValue getKeywordValue(String keyword, JsonValue defaultValue)
Returns the value of the specified schema keyword as aJsonValue.- Parameters:
keyword- the name of the schema keyword, such as"type".defaultValue- the value to be returned if this schema does not contain the keyword. This value can benull.- Returns:
- keyword value if this schema contains the keyword, or
defaultValueif this schema does not contain the keyword. - Throws:
NullPointerException- if the specifiedkeywordisnull.
-
getSubschemas
default Stream<JsonSchema> getSubschemas()
Returns all of the subschemas contained in this schema.- Returns:
- the stream of subschemas contained in this schema.
-
getInPlaceSubschemas
default Stream<JsonSchema> getInPlaceSubschemas()
Returns all of the subschemas of this schema which will be applied to the same instance location as this one.- Returns:
- the stream of subschemas.
-
getSubschemaAt
default JsonSchema getSubschemaAt(String jsonPointer)
Returns the subschema at the location specified with a JSON pointer.- Parameters:
jsonPointer- the valid escaped JSON Pointer string. It must be an empty string or a sequence of '/' prefixed tokens.- Returns:
- the subschema found or
nullif the specified subschema does not exist. - Throws:
NullPointerException- if the specifiedjsonPointerisnull.JsonException- if the specifiedjsonPointeris not a valid JSON Pointer.
-
createEvaluator
Evaluator createEvaluator(EvaluatorContext context, InstanceType type)
Creates an evaluator of this schema.Note that this method is not intended to be used directly by end users.
- Parameters:
context- the context where the evaluator will reside.type- the type of the JSON instance against which this schema will be evaluated. For integers,InstanceType.NUMBERwill be passed instead ofInstanceType.INTEGER.- Returns:
- newly created evaluator. It must not be
null. - Throws:
NullPointerException- if the specifiedtypeisnull.
-
createNegatedEvaluator
Evaluator createNegatedEvaluator(EvaluatorContext context, InstanceType type)
Creates an evaluator of the negated version of this schema.Note that this method is not intended to be used directly by end users.
- Parameters:
context- the context where the evaluator will reside.type- the type of the JSON instance against which this schema will be evaluated. For integers,InstanceType.NUMBERwill be passed instead ofInstanceType.INTEGER.- Returns:
- newly created evaluator. It must not be
null. - Throws:
NullPointerException- if the specifiedtypeisnull.
-
getJsonValueType
JsonValue.ValueType getJsonValueType()
Returns the value type of JSON representing this schema.- Returns:
- the value type of JSON.
-
toJson
JsonValue toJson()
Returns the JSON representation of this schema.- Returns:
- the JSON representation of this schema, never be
null.
-
toString
String toString()
Returns the string representation of this schema.- Overrides:
toStringin classObject- Returns:
- the string representation of this schema, never be
null. - Throws:
JsonException- if an error occurred while generating a JSON.
-
valueOf
static JsonSchema valueOf(boolean value)
Returns a boolean schema instance representing the specified boolean value.
-
-