Attribute Groups

  • style - controls simple value style (as attribute or element)
  • name - defines XML attribute or element name
  • object - provides options for Java object handling
  • property - controls how a value is accessed from a Java object
  • structure - define ordering and reuse of lists of child binding components
  • string - define conversions between Java property values and text representations

All these attributes are optional unless stated otherwise.

style

value-style

Defines the binding style for simple values. The allowed values are "element" (values as child elements with only text content) or "attribute" (values as attributes).

name

name

Local (unqualified) name of element or attribute.

ns

Gives the namespace URI for the element or attribute name. If this is not used the default value is the innermost default namespace for this type, if any.

object

factory

Defines a factory method for constructing new instances of an object type. This applies to bindings for unmarshalling only, and if supplied it must be in the form of a fully-qualified class and method name (e.g., "com.sosnoski.jibx.ObjectBuilderFactory.newInstance" specifies the newInstance() method of the ObjectBuilderFactory class in the com.sosnoski.jibx package) for a static method returning an instance of the bound class. As with the other methods in this group (pre-set, post-set, and pre-get), three different method signatures are allowed: No arguments; a single argument of type java.lang.Object, in which case the owning object is passed in the method call; or a single argument of type org.jibx.runtime.IUnmarshallingContext, in which case the unmarshalling context is passed in the method call (this allows access to the entire stack of objects being unmarshalled). If not supplied, instances of the bound class are constructed using a null argument constructor.

pre-set

Defines a bound class method called on new instances of the class before they are populated with data from unmarshalling. This can be used for any initialization or special handling required before a constructed instance is used. Three different method signatures are supported, as described in the factory attribute text.

post-set

Defines a bound class method called on instances of the class after they are populated with data from unmarshalling. This can be used for any postprocessing or validation required by the class. Three different method signatures are supported, as described in the factory attribute text.

pre-get

Defines a bound class method called on new instances of the class before they are marshalled. This can be used for any preprocessing or validation required by the class. Three different method signatures are supported, as described in the factory attribute text.

marshaller

Defines a custom serialization handler class, as the fully-qualified name of a class implementing the org.jibx.runtime.Marshaller interface. This is only allowed with an output binding; it is required if an unmarshaller is defined for an input-output binding.

unmarshaller

Defines a custom deserialization handler class, as the fully-qualified name of a class implementing the org.jibx.runtime.Unmarshaller interface. This attribute cannot be used in combination with the factory, or pre-set attributes. It is only allowed with an input binding; it is required if a marshaller is defined for an input-output binding.

property

field

Gives the name of the field within the containing class that supplies the property value. This is required except for auto-generated identity fields, for values from a collection, or when both get-method (for output bindings) and set-method (for input bindings) definitions are supplied.

type

Supplies the fully-qualified class name for the property value. This can be used to force a more specific type for a property value defined by the field definition or access method signature as either a base class or an interface.

usage

Defines the usage requirement for this property. The value can either be "required" (property is always present, the default if not specified) or "optional" (property is optional).

test-method

Defines a method for checking if an optional property is present in an instance of the containing class. This is the name of a no-argument method with return type boolean, which must return true if the property is present and false if it is not present. This is only allowed in combination with usage="optional". If not specified, a simple == comparison is used with primitive types to check for a value different from the default, and a equals() comparison for object types with non-null defaults

get-method

Defines a "get" method for retrieving the property value from an instance of the containing class. This is the name of a no-argument method returning a value (primitive or object)

set-method

Defines a "set" method for storing the property value in an instance of the containing class. This is the name of a method with return type void, taking a single value (primitive or object) as a parameter. If both get-method and set-method are defined, the set-method parameter type must be the same as the get-method return value.

structure

ordered

Defines whether child binding definitions represent an ordered list (value "true", the default) or an unordered set ("false"). Only optional child definitions are allowed within an unordered set.

choice

Defines whether child binding definitions represent a choice between alternatives, with only one allowed (value "true") or a set of possibilities of which one or more may be present ("false", the default). A "true" value for this attribute is only allowed when all child definitions are elements (no attributes or text), and also requires ordered="false". This attribute is ignored on a collection element.

label

Gives a label allowing the list of child components to be referenced from elsewhere in the binding definition. Note that this technique has been deprecated, and will not be supported in JiBX 2.0. In most cases an abstract mapping can be used as a replacement.

using

References a list of child components defined elsewhere in the binding definition. The value must match the label value used on a mapping, structure, or collection element somewhere in the binding definition. The child binding components of the referenced element are used as the content of the element making the reference. The object types associated with the binding definition element making the reference and that defining the reference must match, and the order established by the element that defined the reference determines whether the child definitions are considered as ordered or unordered. The element with this attribute must not have any child definitions. Note that this technique has been deprecated, and will not be supported in JiBX 2.0. In most cases an abstract mapping can be used as a replacement.

string

default

Gives the default value for a conversion. This is only allowed for optional properties. If not specified, the default for primitive types is the same as the member variable initial state defined by the JLS, and for object types is "null".

serializer

Defines a custom serialization handler method, as the fully-qualified name of a static method with the signature String xxxx(Target value), where xxxx is the method name and Target is the type of the property (primitive or object type).

deserializer

Defines a custom deserialization handler method, as the fully-qualified name of a static method with the signature Target xxxx(String text), where xxxx is the method name and Target is the type of the property (primitive or object type). Note that when a custom deserialization handler method is used for an optional object type with no default value, that method will be called with a null argument when the corresponding value is missing in the input document. It's up to the handler method to handle this case appropriately (by returning either a null or an object of the expected type).