users@jaxb.java.net

Re: JAXB 2.0 default values

From: Ed Mooney <Ed.Mooney_at_Sun.COM>
Date: Wed, 01 Feb 2006 15:46:53 -0500

Hi Michael,

Attaching an app that does what you want:

     xjc.sh test.xsd;javac `find . -name '*.java'`;java test
     parsing a schema...
     compiling a schema...
     generated\ObjectFactory.java
     0

   -- Ed

Michael C. Bruton wrote:
> Hi.
>
> By the way, I wish what Joe Fialli wrote below, "If an empty element
> is encountered, unmarshalling
> sets the property to the default value," were true for me!
> I am using JAXB 1.6, and I defined an element like this, trying (with
> no working example in the XML primer that I could find) this:
>
> <xsd:element name="RoutingNumber" default="0">
> <xsd:simpleType>
> <xsd:restriction base="xsd:unsignedInt">
> <xsd:maxInclusive value="999999999"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
>
> JAXB will not plug in the default value when I run the app over the
> generated classes. I get an error, "Content of element "RoutingNumber"
> is incomplete"
>
> If anyone knows how to use default at the element (not attribute)
> level with JAXB, I sure would like to know it.
>
> Better yet, I would like to know how to define in a schema a numeric
> element (unsignedLong, unsignedInt, unsignedShort or the like) that may
> either have a value or be empty. Currently I'm using <xsd:union
> memberTypes="NineDigits Empty"/> to get it to happen, and in the java I
> then have to test with instanceof and cast the returned object
> everytime. There must be an easier way! I'm using JAXB to save time
> while maintaining data integrity.
> Anyway, don't know if anyone will see this. Thanks.
>
> - Mike Bruton
>
>
[ ... ]