Package org.everit.json.schema
Class Schema
java.lang.Object
org.everit.json.schema.Schema
- Direct Known Subclasses:
ArraySchema,BooleanSchema,CombinedSchema,ConditionalSchema,ConstSchema,EmptySchema,EnumSchema,FalseSchema,NotSchema,NullSchema,NumberSchema,ObjectSchema,ReferenceSchema,StringSchema
Superclass of all other schema validator classes of this package.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSchema.Builder<S extends Schema>Abstract builder class for the builder classes ofSchemasubclasses. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanSince we add state in subclasses, but want those subclasses to be non final, this allows us to have equals methods that satisfy the equals contract.booleandefinesProperty(String field) Determines if thisSchemainstance defines any restrictions for the object property denoted byfield.voiddescribeTo(JSONPrinter writer) Describes the instance as a JSONObject towriter.booleanprotected ValidationExceptionDeprecated.protected ValidationExceptionDeprecated.getId()getTitle()Returns the properties of the original schema JSON which aren't keywords of json schema (therefore they weren't recognized during schema loading).booleaninthashCode()toString()voidPerforms the schema validation.
-
Field Details
-
schemaLocation
Deprecated.
-
-
Constructor Details
-
Schema
Constructor.- Parameters:
builder- the builder containing the optional title, description and id attributes of the schema
-
-
Method Details
-
validate
Performs the schema validation.- Parameters:
subject- the object to be validated- Throws:
ValidationException- if thesubjectis invalid against this schema.
-
definesProperty
Determines if thisSchemainstance defines any restrictions for the object property denoted byfield. Thefieldshould be a JSON pointer, denoting the property to be queried.For example the field
"#/rectangle/a"is defined by the following schema:
You can also check if a subschema of an array defines a property. In that case, to traverse the array, you can either use an integer array index, or theobjectWithSchemaRectangleDep" : { "type" : "object", "dependencies" : { "d" : { "type" : "object", "properties" : { "rectangle" : { "$ref" : "#/definitions/Rectangle" }, "list": { "type": "array", "items": { "properties": { "prop": {} } }, "minItems": 2, "maxItems: 3 } } } }, "definitions" : { "size" : { "type" : "number", "minimum" : 0 }, "Rectangle" : { "type" : "object", "properties" : { "a" : {"$ref" : "#/definitions/size"}, "b" : {"$ref" : "#/definitions/size"} } } } }"all"or"any"meta-indexes. For example, in the above schemadefinesProperty("#/list/any/prop")returnstruedefinesProperty("#/list/all/prop")returnstruedefinesProperty("#/list/1/prop")returnstruedefinesProperty("#/list/1/nonexistent")returnsfalse(the property is not present in the subschema)definesProperty("#/list/8/prop")returnsfalse(the"list"does not define property8, since"maxItems"is3)
- Parameters:
field- should be a JSON pointer in its string representation.- Returns:
trueif the propertty denoted byfieldis defined by this schema instance
-
equals
-
hashCode
public int hashCode() -
getTitle
-
getDescription
-
getId
-
getSchemaLocation
-
getLocation
-
getDefaultValue
-
hasDefaultValue
public boolean hasDefaultValue() -
isNullable
-
isReadOnly
-
isWriteOnly
-
getUnprocessedProperties
Returns the properties of the original schema JSON which aren't keywords of json schema (therefore they weren't recognized during schema loading). -
describeTo
Describes the instance as a JSONObject towriter.First it adds the
"title,"description"and"id"properties then callsdescribePropertiesTo(JSONPrinter), which will add the subclass-specific properties.It is used by
toString()to serialize the schema instance into its JSON representation.- Parameters:
writer- it will receive the schema description
-
toString
-
failure
Deprecated. -
failure
Deprecated. -
canEqual
Since we add state in subclasses, but want those subclasses to be non final, this allows us to have equals methods that satisfy the equals contract.http://www.artima.com/lejava/articles/equality.html
- Parameters:
other- the subject of comparison- Returns:
trueifthiscan be equal toother
-