Binding XML Schemas

This section describes the default XML-to-Java bindings used by JAXB. All of these bindings can be overridden globally or case-by-case by using a custom binding declaration. See the JAXB Specification for complete information about the default JAXB bindings.

Simple Type Definitions

A schema component using a simple type definition typically binds to a Java property. Because there are different kinds of schema components, the following Java property attributes (common to the schema components) include:

  • Base type

  • Collection type, if any

  • Predicate

The rest of the Java property attributes are specified in the schema component using the simple type definition.

Default Data Type Bindings

The following sections explain the default schema-to-Java, JAXBElement , and Java-to-schema data type bindings.

Schema-to-Java Mapping

The Java language provides a richer set of data types than the XML schema. The following table provides a mapping of XML data types to Java data types in JAXB.

Table: JAXB Mapping of XML Schema Built-in Data Types

XML Schema TypeJava Data Type
xsd:stringjava\.lang\.String
xsd:integerjava\.math\.BigInteger
xsd:intint
xsd\.longlong
xsd:shortshort
xsd:decimaljava\.math\.BigDecimal
xsd:floatfloat
xsd:doubledouble
xsd:booleanboolean
xsd:bytebyte
xsd:QNamejavax\.xml\.namespace\.QName
xsd:dateTimejavax\.xml\.datatype\.XMLGregorianCalendar
xsd:base64Binarybyte\[\]
xsd:hexBinarybyte\[\]
xsd:unsignedIntlong
xsd:unsignedShortint
xsd:unsignedByteshort
xsd:timejavax\.xml\.datatype\.XMLGregorianCalendar
xsd:datejavax\.xml\.datatype\.XMLGregorianCalendar
xsd:gjavax\.xml\.datatype\.XMLGregorianCalendar
xsd:anySimpleTypejava\.lang\.Object
xsd:anySimpleTypejava\.lang\.String
xsd:durationjavax\.xml\.datatype\.Duration
xsd:NOTATIONjavax\.xml\.namespace\.QName

JAXBElement Object

When XML element information cannot be inferred by the derived Java representation of the XML content, a JAXBElement object is provided. This object has methods to get and set the object name and object value.

Java-to-Schema Mapping

The following table shows the default mapping of Java classes to XML data types.

Table: JAXB Mapping of XML Data Types to Java Classes

Java ClassXML Data Type
java\.lang\.Stringxs:string
java\.math\.BigIntegerxs:integer
java\.math\.BigDecimalxs:decimal
java\.util\.Calendarxs:dateTime
java\.util\.Datexs:dateTime
javax\.xml\.namespace\.QNamexs:QName
java\.net\.URIxs:string
javax\.xml\.datatype\.XMLGregorianCalendarxs:anySimpleType
javax\.xml\.datatype\.Durationxs:duration
java\.lang\.Objectxs:anyType
java\.awt\.Imagexs:base64Binary
javax\.activation\.DataHandlerxs:base64Binary
javax\.xml\.transform\.Sourcexs:base64Binary
java\.util\.UUIDxs:string