What is JAXB in Java? JAXB: Java Architecture for XML Binding to convert java object to XML and XML to java object. Learn Features of JAXB, advantages of JAXB.
1. What is JAXB in Java
In 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.
2. What is intent of JAXB
In this post, I tried to demonstrate the basic things of JAXB by using simple example. There are two main intent in JAXB, as follows:
- Marshalling – Convert a Java object into a XML file/content.
- Unmarshalling – Convert XML content into a Java Object.
3. 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.
For JDK < 1.6, download JAXB from java or any site, and puts
jaxb-api.jar
and jaxb-impl.jar
on your project classpath.4. High Level Overview of JAXB
5. 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, aURL
, aDOM node
, or atransformed source
. - Similarly we can marshal XMl content tree to different data targets.
6. 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.
Visit Java tutorial for more details
7. Reference
Visit Oracle Java Official Site for more details.
Your comment is welcome to improve this post of What is JAXB in Java?. Happy Learning! 🙂
Pingback: Shivani
Pingback: abhi