users@jaxb.java.net

Unexpected marshal result

From: Max Ott <max_at_SEMANDEX.NET>
Date: Thu, 12 Dec 2002 15:12:46 -0700

This message was originally submitted by max_at_SEMANDEX.NET to the JAXB-INTEREST
list at JAVA.SUN.COM. If you simply forward it back to the list, using a mail
command that generates "Resent-" fields (ask your local user support or consult
the documentation of your mail program if in doubt), it will be distributed and
the explanations you are now reading will be removed automatically. If on the
other hand you edit the contributions you receive into a digest, you will have
to remove this paragraph manually. Finally, you should be able to contact the
author of this message by using the normal "reply" function of your mail
program.

----------------- Message requiring your approval (36 lines) ------------------
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