users@jaxb.java.net

Re: Handling uninitialized "boolean" elements

From: William M. Saxton <saxton_at_gmail.com>
Date: Fri, 7 Sep 2007 09:42:44 -0400

Ah, not being an XML guru, I was under the assumption that the
defaults were minoccurs="0" maxoccurs="unbounded". It looks like its
"1" / "1".

Thanks for the help!

-Bill

/**
     * Gets the value of the autoNegotiation property.
     *
     */
    public boolean isAutoNegotiation() {
        return autoNegotiation;
    }

On 9/7/07, Kenny MacLeod <kennym_at_kizoom.com> wrote:
> 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
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>