JAXB stands for Java Architecture for XML Binding. JAXB is used in converting XML to Java Object and vice verse which means:
- Marshalling : Convert Java Object → XML
- UnMarshalling : Convert XML → Java Object
As XML is used as an easy means to transport data in Internet, JAXB helps in seamless usage of the data.
Pre-Requestic
JAXB is bundle with JDK 1.6 and later. But if you are using pre JDK 1.6 version, the jar file need to be added at the classpath.
Assuming maven is used, add this dependency:
Core Usage
The usage of this feature can be seen from top as:
- Annotate the Java Object: Details list of annotation
- call marshall() and unmarshall() method.
JAXB Usage for movie description.
First we need to create a Java Object and annotate them with JAXB annotation specification.
Now to Marshall the Java Object to the XML.
Now to UnMarshall, XML to Object
Download the whole code.
References
Oracle JAXB
Oracle JAXB Annotation details
JAXB Project