03 Marshalling and Unmarshalling

Marshalling - is the process of converting Java objects into xml.

Unmarshalling - is the process of converting XML into Java Objects.

We do this in webservice world or the frameworks like Apache CXF or SOA Engines within Apache CXF.

Step to Marshall

  1. Right click on source → main → new class

  2. Choose option to Main Method and then Give a class name

  3. We start it by creating the JAXBContext.
    ex. JAXBContext context = JAXBContext.newInstance(XYZClass.class);

  4. Next create a Marshaller → context.createMarshaller();

  5. Now create a class object → ex. XYZClass xyz = new XYZClass();

Steps to Deserialize

  1. Create a instance of Unmarshaller
    ex. Unmarshaller unmarshaller = context.createUnmarshaller();

  2. Create a reader
    XYZClass xyz = unmarshaller.unmarshal( new StringReader( writer.toString() ));

Full Code

Question 1: The process of converting java objects in to XML is called → Marshalling

  • Compiling

  • Unmarshalling

  • Marshalling

  • Deserialization


Question 2: The entry point in to the JAXB Runtime API is → JAXBContext

  • Marshaller

  • JAXBContext

  • xjc

  • schemagen