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

public abstract class Schema extends Object
Superclass of all other schema validator classes of this package.
  • Field Details

  • Constructor Details

    • Schema

      protected Schema(Schema.Builder<?> builder)
      Constructor.
      Parameters:
      builder - the builder containing the optional title, description and id attributes of the schema
  • Method Details

    • validate

      public void validate(Object subject)
      Performs the schema validation.
      Parameters:
      subject - the object to be validated
      Throws:
      ValidationException - if the subject is invalid against this schema.
    • definesProperty

      public boolean definesProperty(String field)
      Determines if this Schema instance defines any restrictions for the object property denoted by field. The field should be a JSON pointer, denoting the property to be queried.

      For example the field "#/rectangle/a" is defined by the following schema:

       
       objectWithSchemaRectangleDep" : {
         "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"}
                 }
             }
          }
       }
       
       
      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 the "all" or "any" meta-indexes. For example, in the above schema
      • definesProperty("#/list/any/prop") returns true
      • definesProperty("#/list/all/prop") returns true
      • definesProperty("#/list/1/prop") returns true
      • definesProperty("#/list/1/nonexistent") returns false (the property is not present in the subschema)
      • definesProperty("#/list/8/prop") returns false (the "list" does not define property 8, since "maxItems" is 3)
      The default implementation of this method always returns false.
      Parameters:
      field - should be a JSON pointer in its string representation.
      Returns:
      true if the propertty denoted by field is defined by this schema instance
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getTitle

      public String getTitle()
    • getDescription

      public String getDescription()
    • getId

      public String getId()
    • getSchemaLocation

      public String getSchemaLocation()
    • getLocation

      public SchemaLocation getLocation()
    • getDefaultValue

      public Object getDefaultValue()
    • hasDefaultValue

      public boolean hasDefaultValue()
    • isNullable

      public Boolean isNullable()
    • isReadOnly

      public Boolean isReadOnly()
    • isWriteOnly

      public Boolean isWriteOnly()
    • getUnprocessedProperties

      public Map<String,Object> 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

      public void describeTo(JSONPrinter writer)
      Describes the instance as a JSONObject to writer.

      First it adds the "title , "description" and "id" properties then calls describePropertiesTo(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

      public String toString()
      Overrides:
      toString in class Object
    • failure

      @Deprecated protected ValidationException failure(String message, String keyword)
      Deprecated.
    • failure

      @Deprecated protected ValidationException failure(Class<?> expectedType, Object actualValue)
      Deprecated.
    • canEqual

      protected boolean canEqual(Object other)
      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:
      true if this can be equal to other