Using the JAXB Wizard and Code-Seeder Palette

Marshal JAXB Object

The Marshal palette icon action generates template code to marshal a JAXB object. This provides the ability to convert a Java object tree back into XML data. There is no difference between marshalling a content tree that is created manually using the factory methods and marshalling a content tree that is the result of an unmarshal operation. Clients can marshal a Java content tree back to XML data to a java.io.OutputStream or a java.io.Writer. You must know the Class name of the object you are trying to marshal. You can search for the class using the Find... button. The template code can be generated to marshal a JAXB object to a String, OutputStream, File, Writer, or byte array.


Note –

The Code-Seeder currently generates code using a single package name in the context path. You may want to edit the code if more than one package name is needed in the context path.


ProcedureTo Generate Code Using the Marshal JAXB Object

  1. To marshal an existing JAXB class object, drag and drop the JAXB Marshal palette icon to IDE editor.

    The Generate JAXB Marshal codedialog box is displayed.

    Figure 1–7 JAXB Marshal Object

    JAXB Marshal Object

  2. Enter the JAXB object's class name or use the Find... button to search for the class. (as in the Construct's Figure 1–3section)

  3. Select the Marshal To option. You can generate the code from a marshal JAXB object to one of String, Writer, OutputStream, JMSTextMessage, or File.

    Figure 1–8 Select Marshal To

    Marshal To

    The desired method will be generated (as shown below).

    Figure 1–9 Marshal Generated Method

    Marshal generated method