Jakarta XML Binding explained

Programming Language:Java

Jakarta XML Binding (JAXB; formerly Java Architecture for XML Binding) is a software framework that allows Java 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 (formerly Java EE), part of the Java Web Services Development Pack (JWSDP), and one of the foundations for WSIT. It was also part of the Java SE platform (in version Java SE 6–10). As of Java SE 11, JAXB was removed. For details, see JEP 320.

JAXB 1.0 was released in 2003, having been developed under the Java Community Process as JSR 31.[1] In 2006 JAXB 2.0 was released under JSR 222 and Maintenance Release 2 released in December 2009.[2] Reference implementations for these specifications were available under the CDDL open source license at java.net.

Usage

The tool "" can be used to convert XML Schema and other schema file types (as of Java 1.6, RELAX NG, XML DTD, and WSDL are supported experimentally) to class representations.[3] Classes are marked up using annotations from namespace, for example, and . XML list sequences are represented by attributes of type . Marshallers and Unmarshallers are created through an instance of JAXBContext.

In addition, JAXB includes a "" tool that can essentially perform the inverse of "", creating an XML Schema from a set of annotated classes.

Default data type bindings

The table below lists the mappings of XML Schema (XSD) data types to Java data types in JAXB.[4]

XML Schema TypeJava Data Type
xsd:stringjava.lang.String
xsd:integerjava.math.BigInteger
xsd:positiveIntegerjava.math.BigInteger
xsd:int'''int'''
xsd:long '''long'''
xsd:short'''short'''
xsd:decimal java.math.BigDecimal
xsd:float'''float'''
xsd:double '''double'''
xsd:boolean'''boolean'''
xsd:byte'''byte'''
xsd:QName javax.xml.namespace.QName
xsd:dateTimejavax.xml.datatype.XMLGregorianCalendar
xsd:base64Binary'''byte[]'''
xsd:hexBinary'''byte[]'''
xsd:unsignedInt'''long'''
xsd:unsignedShort'''int'''
xsd:unsignedByte'''short'''
xsd:unsignedLongjava.math.BigDecimal
xsd:timejavax.xml.datatype.XMLGregorianCalendar
xsd:datejavax.xml.datatype.XMLGregorianCalendar
xsd:gjavax.xml.datatype.XMLGregorianCalendar
xsd:anySimpleType[5] java.lang.Object
xsd:anySimpleType[6] java.lang.String
xsd:durationjavax.xml.datatype.Duration
xsd:NOTATIONjavax.xml.namespace.QName

Versions

See also

External links

Articles

Notes and References

  1. Web site: JSRs: Java Specification Requests. JSR 31: XML Data Binding Specification . 2011-02-15.
  2. Web site: JSRs: Java Specification Requests. JSR 222: Java Architecture for XML Binding (JAXB) 2.0 . 2011-02-15.
  3. Web site: xjc - Java Architecture for XML Binding . 2011-02-15.
  4. Web site: Using JAXB Data Binding: Standard Data Type Mapping.
  5. for xsd:element of this type
  6. for xsd:attribute of this type
  7. Web site: Which JAXB RI is included in which JDK?.
  8. Web site: Deprecated module java.xml.bind.
  9. Web site: Jaxb 2.2.8 (JDK 8) . 2015-03-01.
  10. Web site: Java SE 7: Java XML Technology Enhancements . 2012-03-21.
  11. Web site: Java SE 6: Features and Enhancements . 2012-03-21.