Chapter 5. Marshalling

Now that you have made it this far, you should start to feel pretty confident. Class generation got you started, and now you have cruised through unmarshalling. Marshalling is almost an exact mirror image of the unmarshalling process, so it should be a real snap at this point. I begin, as has been my custom, by taking the marshalling process flow step by step at a high level. This will give you the perspective needed for the detailed sections in the rest of the chapter.

Once you’ve got a handle on the basic flow, you’ll learn how to take your Java objects and validate the data in them. This ensures that the XML resulting from your Java objects is still legal data for the original data constraints. Then you’ll move on to the actual conversion from Java to XML and look at the resultant XML created from this process. Finally, I touch on creating process loops, where data is converted from XML to Java, back to XML, and then back to Java.

Process Flow

By now, you should know the drill here. As in unmarshalling, there are three basic steps in converting a Java object (or set of objects) to XML. They are listed here and then detailed in the following sections:

  1. Validate Java objects to ensure data validity.

  2. Convert Java data objects into XML documents.

  3. Use/store the resultant XML documents.

Java Objects

The first step, validation of Java objects, assumes that you already have Java objects available for conversion to XML. Along with this assumption is another detail ...

Get Java & XML Data Binding now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.