users@jaxb.java.net

Trying to understand marshaller behavior

From: Max Ott <max_at_SEMANDEX.NET>
Date: Fri, 13 Dec 2002 16:01:52 -0700

Hi,

I'm trying to understand the marshaller and added marshal instructions into the userguide/Sample1/Main.java. Specifically, immediately after the
unmarshal instructions and then for the first address:

            PurchaseOrder po =
                (PurchaseOrder)u.unmarshal( new FileInputStream(url.getFile()) );
            m.marshal(po, System.out);

            // examine some of the content in the PurchaseOrder
            System.out.println( "Ship the following items to: " );

            // display the shipping address
            USAddress address = po.getShipTo();
            m.marshal(address, System.out);

Now, when running I get the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20-05:00"><shipTo country="US"><name>Alice Smith</name>....

Ship the following items to:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Cambridge</city>
<state>MA</state>
<zip>12345</zip>

In the first case I get the whole thing back without any formatting added and starting with "purchaseOrder", while in the second case, I get newlines, and no bracketing <shipTo country="US">.

I don't understand the formatting differences, I do somehow understand why the "shipTo" is omitted, but not completely (where is the country attribute?). Whatever the case maybe, how can I get it to include "shipTo" when marshalling the address?

Thanks,

-max