users@jaxb.java.net

Handling uninitialized "boolean" elements

From: William M. Saxton <saxton_at_gmail.com>
Date: Thu, 6 Sep 2007 15:59:18 -0400

I'm curious how people handle boolean-type elements in the JAXB
created classes if you don't specify a default for the element so that
the element, itself, might not exist.

For example, if my schema contains:

<xsd:element name="foo" ref="fooType" />

<xsd:complexType name="fooType">
        <xsd:sequence>
            <xsd:element name="bar" type="xsd:boolean"/>
        </xsd:sequence>
</xsd:complexType>

Then it is possible to have XML data in the form:

<foo></foo>

So when you use your JAXB converted class:

FooType foo = new Footype();
System.out.println(foo.isBar());

You have problems.

Should I just convert these elements to string-types and be done with
it? I don't want to necessarily initialize them if the value is
unknown...I'd rather just not have the element @ all. It doesn't
seem like Java, however, can handle this properly.