users@jaxb.java.net

Doubles and Integers

From: Marcus Walls <marcus.walls_at_ASPECTIVE.COM>
Date: Fri, 01 Aug 2003 08:52:24 -0600

My schema has a number of elements of the type xsd:int and xsd:double.
Some of these elements are considered non-mandatory by my application, and
I have therefore set the minOccurs and maxOccurs attributes to be 0 and 1
respectively.

This works fine up to a point: if a correct number is specified
everything's good, and if the element is not specified then it's also fine.

However, I'd like to be able to leave the element blank and treat this in
the same way as if the element had actually not been specified.

i.e.

   <a></a> b is not defined
   <a><b>5</b></a> b is 5
   <a><b/></a> b is not defined - currently not supported
   <a><b></b></a> b is not defined - currently not supported

The last two cases will cause a NullPointerException and an error:
unexpected text ""

Is the behaviour I desire possible to achieve with JAXB, or is the
requirement to differentiate between absent and empty elements going to
prevent this.

Assuming it is not possible, what is the best way to achieve this
functionality?

I'm thinking that I may need to create my own data-type with print and
parse methods, but I'm not sure what I'd derive from. e.g. I could create
my own double type derived from xsd:string, but wouldn't my member
variables then be Strings rather than double or java.lang.Double?

Any help, or ideas much appreciated.

Thanks

Marcus