Jakarta XML Binding


Jakarta XML Binding is a software framework that allows Jakarta EE developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure. It is similar to xsd.exe and XmlSerializer in the.NET Framework.
JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error-prone.
JAXB is one of the APIs in the Jakarta EE platform, part of the Java Web Services Development Pack, and one of the foundations for WSIT. It was also part of the Java SE platform. As of Java SE 11, JAXB was removed. For details, see .
JAXB 1.0 was developed under the Java Community Process as JSR 31. In 2006 JAXB 2.0 was released under JSR 222 and Maintenance Release 2 released in December 2009. Reference implementations for these specifications were available under the CDDL open source license at java.net.

Usage

The tool "xjc" can be used to convert XML Schema and other schema file types to class representations. Classes are marked up using annotations from javax.xml.bind.annotation.* namespace, for example, @XmlRootElement and @XmlElement. XML list sequences are represented by attributes of type java.util.List. Marshallers and Unmarshallers are created through an instance of JAXBContext.
In addition, JAXB includes a "schemagen" tool that can essentially perform the inverse of "xjc", creating an XML Schema from a set of annotated classes.

Default data type bindings

The table below lists the mappings of XML Schema data types to Java data types in JAXB.
XML Schema TypeJava Data Type
xsd:stringjava.lang.String
xsd:integerjava.math.BigInteger
xsd:positiveIntegerjava.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:unsignedLongjava.math.BigDecimal
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

Versions