Class JsonSchema
- java.lang.Object
-
- com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchema
-
- Direct Known Subclasses:
HyperSchema
,SimpleTypeSchema
,UnionTypeSchema
public abstract class JsonSchema extends java.lang.Object
The type wraps the json schema specification at : Json JsonSchema DraftJSON (JavaScript Object Notation) JsonSchema defines the media type "application/schema+json", a JSON based format for defining the structure of JSON data. JSON JsonSchema provides a contract for what JSON data is required for a given application and how to interact with it. JSON JsonSchema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data.
JSON (JavaScript Object Notation) JsonSchema is a JSON media type for defining the structure of JSON data. JSON JsonSchema provides a contract for what JSON data is required for a given application and how to interact with it. JSON JsonSchema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data.
An example JSON JsonSchema provided by the JsonSchema draft:{ "name":"Product", "properties":{ "id":{ "type":"number", "description":"Product identifier", "required":true }, "name":{ "description":"Name of the product", "type":"string", "required":true }, "price":{ "required":true, "type": "number", "minimum":0, "required":true }, "tags":{ "type":"array", "items":{ "type":"string" } } }, "links":[ { "rel":"full", "href":"{id}" }, { "rel":"comments", "href":"comments/?id={id}" } ] }
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
$ref
This attribute defines a URI of a schema that contains the full representation of this schema.private java.lang.String
$schema
This attribute defines a URI of a JSON JsonSchema that is the schema of the current schema.private java.lang.String
description
This attribute is a string that provides a full description of the of purpose the instance property.private JsonSchema[]
disallow
This attribute takes the same values as the "type" attribute, however if the instance matches the type or if this value is an array and the instance matches any type or schema in the array, then this instance is not valid.private JsonSchema[]
extendsextends
The value of this property MUST be another schema which will provide a base schema which the current schema will inherit from.private java.lang.String
id
This attribute defines the current URI of this schema (this attribute is effectively a "self" link).private java.lang.Boolean
readonly
This attribute indicates if the instance is not modifiable.private java.lang.Boolean
required
This attribute indicates if the instance must have a value, and not be undefined.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonSchema()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
_equals(JsonSchema that)
protected static <T> boolean
arraysEqual(T[] arr1, T[] arr2)
AnySchema
asAnySchema()
Attempt to return this JsonSchema as anAnySchema
ArraySchema
asArraySchema()
Attempt to return this JsonSchema as anArraySchema
BooleanSchema
asBooleanSchema()
Attempt to return this JsonSchema as aBooleanSchema
ContainerTypeSchema
asContainerSchema()
Deprecated.Since 2.7ContainerTypeSchema
asContainerTypeSchema()
Attempt to return this JsonSchema as aContainerTypeSchema
IntegerSchema
asIntegerSchema()
Attempt to return this JsonSchema as anIntegerSchema
NullSchema
asNullSchema()
Attempt to return this JsonSchema as aNullSchema
NumberSchema
asNumberSchema()
Attempt to return this JsonSchema as aNumberSchema
ObjectSchema
asObjectSchema()
Attempt to return this JsonSchema as anObjectSchema
SimpleTypeSchema
asSimpleTypeSchema()
Attempt to return this JsonSchema as aSimpleTypeSchema
StringSchema
asStringSchema()
Attempt to return this JsonSchema as aStringSchema
UnionTypeSchema
asUnionTypeSchema()
Attempt to return this JsonSchema as anUnionTypeSchema
ValueTypeSchema
asValueSchemaSchema()
Deprecated.Since 2.7ValueTypeSchema
asValueTypeSchema()
Attempt to return this JsonSchema as aValueTypeSchema
void
enrichWithBeanProperty(com.fasterxml.jackson.databind.BeanProperty beanProperty)
Override this to add information specific to the property of bean For example, bean validation annotations could be used to specify value constraints in the schemaboolean
equals(java.lang.Object obj)
protected static boolean
equals(java.lang.Object object1, java.lang.Object object2)
A utility method allowing to easily chain calls to equals() on members without taking any risk regarding the ternary operator precedence.java.lang.String
get$ref()
java.lang.String
get$schema()
java.lang.String
getDescription()
JsonSchema[]
getDisallow()
JsonSchema[]
getExtends()
java.lang.String
getId()
java.lang.Boolean
getReadonly()
java.lang.Boolean
getRequired()
abstract com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes
getType()
boolean
isAnySchema()
determine if this JsonSchema is anAnySchema
.boolean
isArraySchema()
determine if this JsonSchema is anArraySchema
.boolean
isBooleanSchema()
determine if this JsonSchema is anBooleanSchema
.boolean
isContainerTypeSchema()
determine if this JsonSchema is anContainerTypeSchema
.boolean
isIntegerSchema()
determine if this JsonSchema is anIntegerSchema
.boolean
isNullSchema()
determine if this JsonSchema is anNullSchema
.boolean
isNumberSchema()
determine if this JsonSchema is anNumberSchema
.boolean
isObjectSchema()
determine if this JsonSchema is anObjectSchema
.boolean
isSimpleTypeSchema()
determine if this JsonSchema is anSimpleTypeSchema
.boolean
isStringSchema()
determine if this JsonSchema is anStringSchema
.boolean
isUnionTypeSchema()
determine if this JsonSchema is anUnionTypeSchema
.boolean
isValueTypeSchema()
determine if this JsonSchema is anValueTypeSchema
.static JsonSchema
minimalForFormat(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes format)
Create a schema which verifies only that an object is of the given format.void
set$ref(java.lang.String $ref)
void
set$schema(java.lang.String $schema)
void
setDescription(java.lang.String description)
void
setDisallow(JsonSchema[] disallow)
void
setExtends(JsonSchema[] extendsextends)
void
setId(java.lang.String id)
void
setReadonly(java.lang.Boolean readonly)
void
setRequired(java.lang.Boolean required)
-
-
-
Field Detail
-
id
private java.lang.String id
This attribute defines the current URI of this schema (this attribute is effectively a "self" link). This URI MAY be relative or absolute. If the URI is relative it is resolved against the current URI of the parent schema it is contained in. If this schema is not contained in any parent schema, the current URI of the parent schema is held to be the URI under which this schema was addressed. If id is missing, the current URI of a schema is defined to be that of the parent schema. The current URI of the schema is also used to construct relative references such as for $ref.
-
$ref
private java.lang.String $ref
This attribute defines a URI of a schema that contains the full representation of this schema. When a validator encounters this attribute, it SHOULD replace the current schema with the schema referenced by the value's URI (if known and available) and re- validate the instance. This URI MAY be relative or absolute, and relative URIs SHOULD be resolved against the URI of the current schema.
-
$schema
private java.lang.String $schema
This attribute defines a URI of a JSON JsonSchema that is the schema of the current schema. When this attribute is defined, a validator SHOULD use the schema referenced by the value's URI (if known and available) when resolving Hyper JsonSchema (Section 6) links (Section 6.1). A validator MAY use this attribute's value to determine which version of JSON JsonSchema the current schema is written in, and provide the appropriate validation features and behavior. Therefore, it is RECOMMENDED that all schema authors include this attribute in their schemas to prevent conflicts with future JSON JsonSchema specification changes.
-
disallow
private JsonSchema[] disallow
This attribute takes the same values as the "type" attribute, however if the instance matches the type or if this value is an array and the instance matches any type or schema in the array, then this instance is not valid.
-
extendsextends
private JsonSchema[] extendsextends
The value of this property MUST be another schema which will provide a base schema which the current schema will inherit from. The inheritance rules are such that any instance that is valid according to the current schema MUST be valid according to the referenced schema. This MAY also be an array, in which case, the instance MUST be valid for all the schemas in the array. A schema that extends another schema MAY define additional attributes, constrain existing attributes, or add other constraints. Conceptually, the behavior of extends can be seen as validating an instance against all constraints in the extending schema as well as the extended schema(s). More optimized implementations that merge schemas are possible, but are not required. An example of using "extends": { "description":"An adult", "properties":{"age":{"minimum": 21}}, "extends":"person" } { "description":"Extended schema", "properties":{"deprecated":{"type": "boolean"}}, "extends":"http://json-schema.org/draft-03/schema" }
-
required
private java.lang.Boolean required
This attribute indicates if the instance must have a value, and not be undefined. This is false by default, making the instance optional.
-
readonly
private java.lang.Boolean readonly
This attribute indicates if the instance is not modifiable. This is false by default, making the instance modifiable.
-
description
private java.lang.String description
This attribute is a string that provides a full description of the of purpose the instance property.
-
-
Method Detail
-
asAnySchema
public AnySchema asAnySchema()
Attempt to return this JsonSchema as anAnySchema
- Returns:
- this as an AnySchema if possible, or null otherwise
-
asArraySchema
public ArraySchema asArraySchema()
Attempt to return this JsonSchema as anArraySchema
- Returns:
- this as an ArraySchema if possible, or null otherwise
-
asBooleanSchema
public BooleanSchema asBooleanSchema()
Attempt to return this JsonSchema as aBooleanSchema
- Returns:
- this as a BooleanSchema if possible, or null otherwise
-
asContainerSchema
@Deprecated public ContainerTypeSchema asContainerSchema()
Deprecated.Since 2.7
-
asContainerTypeSchema
public ContainerTypeSchema asContainerTypeSchema()
Attempt to return this JsonSchema as aContainerTypeSchema
- Returns:
- this as an ContainerTypeSchema if possible, or null otherwise
- Since:
- 2.7
-
asIntegerSchema
public IntegerSchema asIntegerSchema()
Attempt to return this JsonSchema as anIntegerSchema
- Returns:
- this as an IntegerSchema if possible, or null otherwise
-
asNullSchema
public NullSchema asNullSchema()
Attempt to return this JsonSchema as aNullSchema
- Returns:
- this as a NullSchema if possible, or null otherwise
-
asNumberSchema
public NumberSchema asNumberSchema()
Attempt to return this JsonSchema as aNumberSchema
- Returns:
- this as a NumberSchema if possible, or null otherwise
-
asObjectSchema
public ObjectSchema asObjectSchema()
Attempt to return this JsonSchema as anObjectSchema
- Returns:
- this as an ObjectSchema if possible, or null otherwise
-
asSimpleTypeSchema
public SimpleTypeSchema asSimpleTypeSchema()
Attempt to return this JsonSchema as aSimpleTypeSchema
- Returns:
- this as a SimpleTypeSchema if possible, or null otherwise
-
asStringSchema
public StringSchema asStringSchema()
Attempt to return this JsonSchema as aStringSchema
- Returns:
- this as a StringSchema if possible, or null otherwise
-
asUnionTypeSchema
public UnionTypeSchema asUnionTypeSchema()
Attempt to return this JsonSchema as anUnionTypeSchema
- Returns:
- this as a UnionTypeSchema if possible, or null otherwise
-
asValueSchemaSchema
@Deprecated public ValueTypeSchema asValueSchemaSchema()
Deprecated.Since 2.7
-
asValueTypeSchema
public ValueTypeSchema asValueTypeSchema()
Attempt to return this JsonSchema as aValueTypeSchema
- Returns:
- this as a ValueTypeSchema if possible, or null otherwise
- Since:
- 2.7
-
getId
public java.lang.String getId()
-
get$ref
public java.lang.String get$ref()
-
get$schema
public java.lang.String get$schema()
-
getDisallow
public JsonSchema[] getDisallow()
-
getExtends
public JsonSchema[] getExtends()
-
getRequired
public java.lang.Boolean getRequired()
-
getReadonly
public java.lang.Boolean getReadonly()
-
getDescription
public java.lang.String getDescription()
-
getType
public abstract com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes getType()
-
isAnySchema
public boolean isAnySchema()
determine if this JsonSchema is anAnySchema
.- Returns:
- true if this JsonSchema is an AnySchema, false otherwise
-
isArraySchema
public boolean isArraySchema()
determine if this JsonSchema is anArraySchema
.- Returns:
- true if this JsonSchema is an ArraySchema, false otherwise
-
isBooleanSchema
public boolean isBooleanSchema()
determine if this JsonSchema is anBooleanSchema
.- Returns:
- true if this JsonSchema is an BooleanSchema, false otherwise
-
isContainerTypeSchema
public boolean isContainerTypeSchema()
determine if this JsonSchema is anContainerTypeSchema
.- Returns:
- true if this JsonSchema is an ContainerTypeSchema, false otherwise
-
isIntegerSchema
public boolean isIntegerSchema()
determine if this JsonSchema is anIntegerSchema
.- Returns:
- true if this JsonSchema is an IntegerSchema, false otherwise
-
isNullSchema
public boolean isNullSchema()
determine if this JsonSchema is anNullSchema
.- Returns:
- true if this JsonSchema is an NullSchema, false otherwise
-
isNumberSchema
public boolean isNumberSchema()
determine if this JsonSchema is anNumberSchema
.- Returns:
- true if this JsonSchema is an NumberSchema, false otherwise
-
isObjectSchema
public boolean isObjectSchema()
determine if this JsonSchema is anObjectSchema
.- Returns:
- true if this JsonSchema is an ObjectSchema, false otherwise
-
isSimpleTypeSchema
public boolean isSimpleTypeSchema()
determine if this JsonSchema is anSimpleTypeSchema
.- Returns:
- true if this JsonSchema is an SimpleTypeSchema, false otherwise
-
isStringSchema
public boolean isStringSchema()
determine if this JsonSchema is anStringSchema
.- Returns:
- true if this JsonSchema is an StringSchema, false otherwise
-
isUnionTypeSchema
public boolean isUnionTypeSchema()
determine if this JsonSchema is anUnionTypeSchema
.- Returns:
- true if this JsonSchema is an UnionTypeSchema, false otherwise
-
isValueTypeSchema
public boolean isValueTypeSchema()
determine if this JsonSchema is anValueTypeSchema
.- Returns:
- true if this JsonSchema is an ValueTypeSchema, false otherwise
-
set$ref
public void set$ref(java.lang.String $ref)
-
set$schema
public void set$schema(java.lang.String $schema)
-
setDisallow
public void setDisallow(JsonSchema[] disallow)
-
setExtends
public void setExtends(JsonSchema[] extendsextends)
-
setId
public void setId(java.lang.String id)
-
setRequired
public void setRequired(java.lang.Boolean required)
-
setReadonly
public void setReadonly(java.lang.Boolean readonly)
-
setDescription
public void setDescription(java.lang.String description)
-
enrichWithBeanProperty
public void enrichWithBeanProperty(com.fasterxml.jackson.databind.BeanProperty beanProperty)
Override this to add information specific to the property of bean For example, bean validation annotations could be used to specify value constraints in the schema- Parameters:
beanProperty
-
-
minimalForFormat
public static JsonSchema minimalForFormat(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes format)
Create a schema which verifies only that an object is of the given format.- Parameters:
format
- the format to expect- Returns:
- the schema verifying the given format
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
_equals
protected boolean _equals(JsonSchema that)
-
equals
protected static boolean equals(java.lang.Object object1, java.lang.Object object2)
A utility method allowing to easily chain calls to equals() on members without taking any risk regarding the ternary operator precedence.- Returns:
- (object1 == null ? object2 == null : object1.equals(object2))
-
arraysEqual
protected static <T> boolean arraysEqual(T[] arr1, T[] arr2)
-
-