Friday, 6 January 2012

JAXB Customization / Annotation

  • collectionType="indexed": collection properties as array instead of list properties (get/set, get[]/set[], getLength). The arrays returned and taken are not part of the content object's state
  • optionalProperty (wrapper/primitive/isSet): binding for optional non-nillable element/attribute of primitive base type (use instead of deprecated "generateIsSetMethod")
  • The "definition scope" covers all local attributes that can reference this global attribute declaration. This is useful since it allows the customization to be done once when a global attribute is defined instead of at each local attribute that references the global attribute declaration
  • @XmlRootElement: marks an Object so that it can be marshalled. Fields and properties typically map to local elements within a complex type for a class. But a well formed XML document begins with a root element (a global element in the corresponding schema). The @XmlRootElement annotation can be used to associate a global element with a class or an enum type
  • @XmlTransient prevents the mapping of a Java program element to XML
  • A class usually maps to a complex type. However, using @XmlValue annotation, a class can also be mapped to a simple type (to hold a simple value) or a complexType with simpleContent (to hold a simple value and attributes)
  • @XmlSchemaType allows a customized mapping to a XML Schema built in type. This is useful where a Java type can map to more than one schema built in types, e.g. XMLGregorianCalendar which can represent one of the eight schema built-in types