Objects

Objects are the most complex part of JSD and are declared using the “object” subclass of “type-specifier”.  The “object” class is abstract with two concrete subclasses: “anonymous-class-instance” and “named-class-instance”.

named-class-instance

The “named-class-instance” allows named classes from the “classes” array to be referenced, and defines a single property “object” of type object with the following properties:

class

The “class” property is a string property that specifies the name of the class of the object.

anonymous-class-instance

The “anonymous-class-instance” allows objects (class instances) to be declared anonymously, i.e. without reference to a class definition. This is important in two contexts:

  1. It should be possible to declare a simple schema without defining classes when they are not needed
  2. Classes in the “classes” array must be defined by associating a class name with an otherwise anonymous structure declaration

The “anonymous-class-instance” defines a single property “object” with the following properties:

extends

The “extends” property takes two forms:

  • A string that identifies a single class whose definition is inherited by the defined class
  • An array of strings that identify multiple classes whose definition is inherited by the defined class

In both cases, the defined class will inherit the identity of any extended classes, i.e. an instance of the extending class is considered to be an instance of the extended class.

implements

The “implements” property takes two forms:

  • A string that identifies a single class whose definition is inherited by the defined class
  • An array of strings that identify multiple classes whose definition is inherited by the defined class

In both cases, the defined class will not inherit the identity of any extended classes, i.e. an instance of the implementing class is not considered to be an instance of the implemented class.

properties

The “properties” property is an array of property declarations defined by the “property-specifier” class. The role of the “property-specifier” is primarily to associate a “type-specifier” with a property name, and so the “property-specifier” class implements the “type-specifier” (i.e. a “property-specifier” is not considered to be a “type-specifier”) class and adds the following properties:

name

The “name” property is a string property that defines the name of the property being declared.

The “name” property is optional. If the name property is absent, the type definition implemented from the “type-specifier” class is taken to apply to any instance property name that may occur in the object instance, other than any named properties declared in the “properties” array. Note that multiple unnamed properties may appear in the “properties” array, in which case, the instance document will be considered valid if any relevant instance properties (i.e. ones whose name is not formally declared in the object definition) match any of the unnamed “property-specifier” instances in the “properties” array.

optional

The “optional” property is a boolean property that defines whether the property must be present.

The “optional” property is optional and has a default value of false.

not-null

The “not-null” property is a boolean property that defines whether it is valid for the property to be null.

The “not-null” property is optional and has a default value of false.