Engineering Full Stack Apps with Java and JavaScript
In JAXB2, annotations are used both in generated Java content classes and in Java classes as input to generate schema definitions.
These binding annotations are defined in the javax.xml.bind.annotation package.
Below are some of the more commonly used annotations defined in the javax.xml.bind.annotation package.
XmlAccessorType
Specifies the default serialization of fields and properties
Annotation Elements
AccessType.PUBLIC_MEMBER maps only public fields and JavaBean properties. AccessType.FIELDS maps only fields. AccessType.PROPERTIES maps only JavaBeans properties. AccessType.NONE maps neither fields nor properties.
XmlAttribute
Maps a JavaBean property to an attribute
Annotation Elements
name: Attribute name. namespace: Attribute namespace. required: Specifies whether attribute is required; the default is false.
XmlElement
Maps a JavaBean property to an element
Annotation Elements
defaultValue: The default value of element. name: The element name. namespace: Target namespace of element. nillable: Specifies whether element is nillable; the default is false. type: Element type.
XmlEnum
Maps an enum to a simple type with enumeration
Annotation Elements
value: Enumeration value
XmlList
Maps a property to a list simple type
XmlRootElement
Maps a class to root element
Annotation Elements
name: Local name of root element. namespace: Namespace of root element.
XmlSchema
Maps a package name to a XML namespace
Annotation Elements
attributeFormDefault: Specifies the value of the attributeFormDefault attribute. elementFormDefault: Specifies the value of the attribute elementFormDefault. namespace: XML namespace. xmlns: Maps namespace prefixes to namespace URIs.
XmlType
Maps a class to an XML Schema type, which may be a simple type or a complex type
Annotation Elements
name: Target namespace of the XML Schema type. propOrder: Specifies the order of XML schema elements when a class is mapped to a complex type.
XmlValue
Maps a class to an XML Schema complex type with simpleContent or an XML Schema simple type