javax.xml.bind.annotation |
Defines annotations for customizing Java program elements to XML Schema mapping.
Package Specification
The following table shows the JAXB mapping annotations
that can be associated with each program element.
Program Element |
JAXB annotation |
Package |
|
Class |
|
Enum type |
|
JavaBean Property/field |
|
Parameter |
|
Terminology
JavaBean property and field: For the purposes of
mapping, there is no semantic difference between a field and
a JavaBean property. Thus, an annotation that can be applied
to a JavaBean property can always be applied to a
field. Hence in the Javadoc documentation, for brevity, the
term JavaBean property or property is used to mean either JavaBean
property or a field. Where required, both are explicitly
mentioned.
top level class: For the purpose of mapping, there is
no semantic difference between a top level class and a
static nested class. Thus, an annotation that can be applied
to a top level class, can always be applied to a nested
static class. Hence in the Javadoc documentation, for
brevity, the term "top level class" or just class is used to
mean either a top level class or a nested static
class.
mapping annotation:A JAXB 2.0 defined program
annotation based on the JSR 175 programming annotation
facility.
Common Usage Constraints
The following usage constraints are defined here since
they apply to more than annotation:
- For a property, a given annotation can be applied to
either read or write property but not both.
- A property name must be different from any other
property name in any of the super classes of the
class being mapped.
- A mapped field name or the decapitalized name of a
mapped property must be unique within a class.
Notations
Namespace prefixes
The following namespace prefixes are used in the XML Schema
fragments in this package.
Prefix |
Namespace |
Notes |
xs |
http://www.w3.org/2001/XMLSchema |
Namespace of XML Schema namespace |
ref |
http://ws-i.org/profiles/basic/1.1/xsd |
Namespace for swaref schema component |
xsi |
http://www.w3.org/2001/XMLSchema-instance |
XML Schema namespace for instances |
@since JAXB 2.0
|
Java Source File Name | Type | Comment |
DomHandler.java | Interface | Converts an element (and its descendants)
from/to DOM (or similar) representation.
Implementations of this interface will be used in conjunction with
XmlAnyElement annotation to map an element of XML into a representation
of infoset such as W3C DOM.
Implementations hide how a portion of XML is converted into/from such
DOM-like representation, allowing JAXB providers to work with arbitrary
such library.
This interface is intended to be implemented by library writers
and consumed by JAXB providers. |
W3CDomHandler.java | Class | |
XmlAccessOrder.java | enum | Used by XmlAccessorOrder to control the ordering of properties and
fields in a JAXB bound class. |
XmlAccessorOrder.java | Annotation | Controls the ordering of fields and properties in a class. |
XmlAccessorType.java | Annotation | Controls whether fields or Javabean properties are serialized by default. |
XmlAccessType.java | enum | Used by XmlAccessorType to control serialization of fields or
properties. |
XmlAnyAttribute.java | Annotation |
Maps a JavaBean property to a map of wildcard attributes.
Usage
The @XmlAnyAttribute annotation can be used with the
following program elements:
- JavaBean property
- non static, non transient field
See "Package Specification" in javax.xml.bind.package javadoc for
additional common information.
The usage is subject to the following constraints:
- At most one field or property in a class can be annotated
with @XmlAnyAttribute.
|
XmlAnyElement.java | Annotation | Maps a JavaBean property to XML infoset representation and/or JAXB element.
This annotation serves as a "catch-all" property while unmarshalling
xml content into a instance of a JAXB annotated class. |
XmlAttachmentRef.java | Annotation | Marks a field/property that its XML form is a uri reference to mime content. |
XmlAttribute.java | Annotation |
Maps a JavaBean property to a XML attribute. |
XmlElement.java | Annotation | Maps a JavaBean property to a XML element derived from property name.
Usage
@XmlElement annotation can be used with the following program
elements:
- a JavaBean property
- non static, non transient field
- within
XmlElements
The usage is subject to the following constraints:
- This annotation can be used with following annotations:
XmlID ,
XmlIDREF ,
XmlList ,
XmlSchemaType ,
XmlValue ,
XmlAttachmentRef ,
XmlMimeType ,
XmlInlineBinaryData ,
XmlElementWrapper ,
XmlJavaTypeAdapter
- if the type of JavaBean property is a collection type of
array, an indexed property, or a parameterized list, and
this annotation is used with
XmlElements then,
@XmlElement.type() must be DEFAULT.class since the
collection item type is already known.
|
XmlElementDecl.java | Annotation | Maps a factory method to a XML element.
Usage
The annotation creates a mapping between an XML schema element
declaration and a element factory method that returns a
JAXBElement instance representing the element
declaration. |
XmlElementRef.java | Annotation |
Maps a JavaBean property to a XML element derived from property's type.
Usage
@XmlElementRef annotation can be used with a
JavaBean property or from within
XmlElementRefs
This annotation dynamically associates an XML element name with the JavaBean
property. |
XmlElementRefs.java | Annotation | Marks a property that refers to classes with
XmlElement or JAXBElement. |
XmlElements.java | Annotation |
A container for multiple @
XmlElement annotations.
Multiple annotations of the same type are not allowed on a program
element. |
XmlElementWrapper.java | Annotation | Generates a wrapper element around XML representation.
This is primarily intended to be used to produce a wrapper
XML element around collections. |
XmlEnum.java | Annotation |
Maps an enum type
Enum to XML representation.
This annotation, together with
XmlEnumValue provides a
mapping of enum type to XML representation.
Usage
The @XmlEnum annotation can be used with the
following program elements:
The usage is subject to the following constraints:
See "Package Specification" in javax.xml.bind.package javadoc for
additional common information
An enum type is mapped to a schema simple type with enumeration
facets. |
XmlEnumValue.java | Annotation | Maps an enum constant in
Enum type to XML representation. |
XmlID.java | Annotation |
Maps a JavaBean property to XML ID.
To preserve referential integrity of an object graph across XML
serialization followed by a XML deserialization, requires an object
reference to be marshalled by reference or containment
appropriately. |
XmlIDREF.java | Annotation |
Maps a JavaBean property to XML IDREF.
To preserve referential integrity of an object graph across XML
serialization followed by a XML deserialization, requires an object
reference to be marshalled by reference or containment
appropriately. |
XmlInlineBinaryData.java | Annotation | Disable consideration of XOP encoding for datatypes that are bound to
base64-encoded binary data in XML.
When XOP encoding is enabled as described in
AttachmentMarshaller.isXOPPackage , this annotation disables datatypes such as
Image or
Source or byte[] that are bound to base64-encoded binary from being considered for
XOP encoding. |
XmlList.java | Annotation | Used to map a property to a list simple type.
Usage
The @XmlList annotation can be used with the
following program elements:
When a collection property is annotated just with @XmlElement,
each item in the collection will be wrapped by an element.
For example,
@XmlRootElement
class Foo {
@XmlElement
List<String> data;
}
would produce XML like this:
abc
def
@XmlList annotation, on the other hand, allows multiple values to be
represented as whitespace-separated tokens in a single element. |
XmlMimeType.java | Annotation | Associates the MIME type that controls the XML representation of the property.
This annotation is used in conjunction with datatypes such as
Image or
Source that are bound to base64-encoded binary in XML.
If a property that has this annotation has a sibling property bound to
the xmime:contentType attribute, and if in the instance the property has a value,
the value of the attribute takes precedence and that will control the marshalling. |
XmlMixed.java | Annotation |
Annotate a JavaBean multi-valued property to support mixed content.
The usage is subject to the following constraints:
- can be used with @XmlElementRef, @XmlElementRefs or @XmlAnyElement
The following can be inserted into @XmlMixed annotated multi-valued property
- XML text information items are added as values of java.lang.String.
- Children element information items are added as instances of
JAXBElement or instances with a class that is annotated with
@XmlRootElement.
- Unknown content that is not be bound to a JAXB mapped class is inserted
as
Element .
|
XmlNs.java | Annotation |
Associates a namespace prefix with a XML namespace URI. |
XmlNsForm.java | enum | Enumeration of XML Schema namespace qualifications. |
XmlRegistry.java | Annotation | Marks a class that has
XmlElementDecl s. |
XmlRootElement.java | Annotation | Maps a class or an enum type to an XML element.
Usage
The @XmlRootElement annotation can be used with the following program
elements:
- a top level class
- an enum type
See "Package Specification" in javax.xml.bind.package javadoc for
additional common information.
When a top level class or an enum type is annotated with the
@XmlRootElement annotation, then its value is represented
as XML element in an XML document.
This annotation can be used with the following annotations:
XmlType ,
XmlEnum ,
XmlAccessorType ,
XmlAccessorOrder .
Example 1: Associate an element with XML Schema type
// Example: Code fragment
@XmlRootElement
class Point {
int x;
int y;
Point(int _x,int _y) {x=_x;y=_y;}
}
//Example: Code fragment corresponding to XML output
marshal( new Point(3,5), System.out);
3
5
The annotation causes an global element declaration to be produced
in the schema. |
XmlSchema.java | Annotation | Maps a package name to a XML namespace. |
XmlSchemaType.java | Annotation | Maps a Java type to a simple schema built-in type.
Usage
@XmlSchemaType annotation can be used with the following program
elements:
- a JavaBean property
- field
- package
@XmlSchemaType annotation defined for Java type
applies to all references to the Java type from a property/field. |
XmlSchemaTypes.java | Annotation |
A container for multiple @
XmlSchemaType annotations.
Multiple annotations of the same type are not allowed on a program
element. |
XmlTransient.java | Annotation |
Prevents the mapping of a JavaBean property to XML representation.
The @XmlTransient annotation is useful for resolving name
collisions between a JavaBean property name and a field name or
preventing the mapping of a field/property. |
XmlType.java | Annotation |
Maps a class or an enum type to a XML Schema type.
Usage
The @XmlType annnotation can be used with the following program
elements:
- a top level class
- an enum type
See "Package Specification" in javax.xml.bind.package javadoc for
additional common information.
Mapping a Class
A class maps to a XML Schema type. |
XmlValue.java | Annotation |
Enables mapping a class to a XML Schema complex type with a
simpleContent or a XML Schema simple type. |