users@jaxb.java.net

Re: JAXB 2.0 xs:int binding

From: Kasia Trapszo <kasia_at_trapszo.com>
Date: Mon, 10 Apr 2006 21:11:27 -0400

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have semi-fixed the issue by modifying our schema (which admittedly
is not the best schema in the world) to provide default values for
all optional types that result in primitive java return-types. Which
fixes the issue (somewhat) as isSet still returns false (as it
should) and the getWhatever() call returns the default value.

I do feel that's just a band-aid though and generally allowing auto-
unboxing in this situation is probably not a good idea. I'd prefer to
see the Integer object returned, rather than an int and allow the
programmer to decide if auto-unboxing is warranted. That provides
for more flexibility and and allows for generation of compile
warnings in application code to make the issue easy to spot.


On Apr 10, 2006, at 9:06 PM, Kohsuke Kawaguchi wrote:

> Kasia Trapszo wrote:
>> Unfortunately that causes problems migrating from jaxb 1 to 2.
>> Since the
>> generated code returns a primitive type that is internally stored
>> as an
>> Integer, calling "getSomething" generates a NullPointer exception
>> when
>> that value is not set. That's a lot of code that now has to be
>> changed
>> to first check the "isSet" value when with jaxb 1 it was checking
>> for a
>> int <= 0 value.
>
> I see. What about if you use XSLT to remove all optionality from
> attributes, just for XJC?
>
> I guess you won't be able to detect the absence of an attribute
> though.
>
> You can write a plugin and replace FieldRendererFactory.getSingle()
> and returns a slightly modified version that returns VM-
> uninitialized value, maybe?
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (Darwin)

iD8DBQFEOwJD06QY0YjI75QRAiQFAJ9ewQYMkTwI+7xgIwkmm6bDFzMZTwCfcrUq
yCQ92s3qo/a6/BWm0AynOXo=
=1Xqn
-----END PGP SIGNATURE-----