What is JAXB?

Connect with

Oracle Java

JAXB stands for Java Architecture for XML Binding. By using JAXB and its annotation you can do two following things, in fact your intent is very clear to do the following things.

  • convert Java object to XML
  • XML to Java Object.

In this post, I tried to demonstrate the basic thing of JAXB by using simple example. There are two main intent in JAXB, as follows:

  1. Marshalling – Convert a Java object into a XML file/content.
  2. Unmarshalling – Convert XML content into a Java Object.

1. Pre-requisite for JAXB

It depend upon what version of Java you are using. if using JDK 1.6 or higher then no need of any dependency or jar file in order to run the code or compile the code. If you are using lower version it means less than 1.6 version of JSE or java then you have to use dependency. you can download

Technologies used in this post:

– JDK 1.7
– JAXB 2.0
– Eclipse

once you know the basic concetp , working with JAXB is very easy, just annotate object with JAXB annotation, later use jaxbMarshaller.marshal() or jaxbMarshaller.unmarshal() to do the object / XML conversion.

Note:
For JDK < 1.6, download JAXB from java or any site, and puts jaxb-api.jar and jaxb-impl.jar on your project classpath.

2. High Level Overview of JAXB

jaxb-Java Architecture for xml Binding
jaxb-Java Architecture for xml Binding

3. Advantage of JAXB

  • Simplicity: JAXB is simple to use compared to JAXP (e.g. SAX/DOM.)
  • Access: JAXB allows non-sequential processing of XML documents. In DOM we need to navigate a tree structure and JAXB doesn’t requires such navigation.
  • Java instance: We work with java instances instead of event/elements.
  • Momory efficiency: JAXB uses memory efficiently than DOM.
  • different input source: There are various input source options are available to convert one from another. We can unmarshal XML data from sources: InputStream object, a URL, a DOM node, or a transformed source .
  • Similarly we can marshal XMl content tree to different data targets.

4. Features of JAXB 2.0

In latest version of JAXB i.e. JAXB 2.0 includes several features that were not present in JAXB 1.x.

  • Annotation support: JAXB 2.0 provides support to annotation so less coding is required to develop JAXB application. The javax.xml.bind.annotation package provides classes and interfaces for JAXB 2.0.
  • W3C schema support: JAXB 2.0 supports all the W3C schema unlike JAXB 1.0.
  • Additional Validation Capabilities: it provides additional validation support by JAXP 1.3 validation API.
  • Small Runtime Library: it required small runtime library that JAXB 1.0.
  • Reduces generated schema-derived classes: it reduces a lot of generated schema-derived classes.

Your comment is welcome to improve this post. 🙂


Connect with

2 thoughts on “What is JAXB?

  1. Pingback: Shivani
  2. Pingback: abhi

Leave a Reply

Your email address will not be published. Required fields are marked *