Marshalling means producing a stream of byte which contain enough information to be able to re-build the object. This make no impact on the original object, because it is a read-only operation.


JAXB stand for Java Architecture for XML Binding. Jaxb allows us to map Java classes to XML representations. JAXB can be used Java to marshal java object into xml or/and to unmarshal XML back into Java objects.

I used these 2 jar for this example. You can download latest version of jar and add it to your class path.

  1. jaxb-api-2.1.jar
  2. jaxb-impl-2.1.jar

Marshalling to a File

Marshalling to a SAX ContentHandler

Marshalling to a DOM Node

Marshalling to a

Marshalling to a

Marshalling to a javax.xml.transform.SAXResult

Marshalling to a javax.xml.transform.DOMResult

Marshalling to a javax.xml.transform.StreamResult

Marshalling to a

Marshalling to a

Marshalling example

Here is which we are going to marshalled into xml using Jaxb apis.

Source code of is given below.


Share & Like

About is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.