users@jaxb.java.net

Re: Handling uninitialized "boolean" elements

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Sun, 9 Sep 2007 20:02:17 +0200

Hi.


> 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.

I prefer generating and using "isSet*" properties.

Bye.
/lexi