users@jaxb.java.net

Re: Handling uninitialized "boolean" elements

From: Kenny MacLeod <kennym_at_kizoom.com>
Date: Fri, 07 Sep 2007 07:46:36 +0100

Give your quoted schema fragment, the <bar/> element is not optional, so
<foo></foo> would not pass schema validation.

Because of this, XJC can safely use a java boolean, because there must
be a value.

If you were to make the bar element optional (using minoccurs="0"), then
XJC should generate a Boolean instead of a boolean.



William M. Saxton wrote:
> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>