users@glassfish.java.net

JAXB: Question about XML output for property with value = null

From: <glassfish_at_javadesktop.org>
Date: Tue, 06 Mar 2007 03:51:12 PST

Hi,

i have a question about using JAXB 1.x.

i want to know, for a property with value = null, can i output the corresponding
element in the XML document (created by calling Marshaller.marshal(....)) instead
of just skipping it?

for example, xsd schema (excerpt):

<xsd:complexType name="persion">
<xsd:sequence>

<xsd:element name="name" maxOccurs="1"
                     minOccurs="1" nillable="false" type="xsd:string"/>

<xsd:element name="address" maxOccurs="1"
                     minOccurs="1" nillable="true" type="xsd:string"/>

</xsd:sequence>
</xsd:complexType>

===================================================
class generated:

class Person
{
     setName(...);
     getName(...);

     setAddress(...);
     getAddress(...);

}
====================================

If the Persion.address property of value = null...

the XML output like the following....

<persion>
<name>abc</name>
/* <address> tag not output !!! */
</persion>

======================================

>>>HOW can i get output like the following one?

<persion>
<name>abc</name>
<address xsi:nil="true"/> /*element output with nil=true to indicate null value*/
</persion>

====================================

BTW, i find that for property with type = xsd:dateTime ( java.util.Calendar), the tag is
output even though property value = null (not skipping it)

e.g. <start_date></start_date>

....seems not a consistent behavior..


thank you...
[Message sent by forum member 'imperfect' (imperfect)]

http://forums.java.net/jive/thread.jspa?messageID=206426