Both behaviors are per JAXB spec (and are really part of the JAXB code 
generator and out of our control).    The only option would be to write an XJC 
plugin to change the behavior. 

I THINK there was a collections seetter plugin in jaxb-commons, but with the 
java.net redesign, I have NO idea where it went.   Fisheye still has some info 
on it:

http://fisheye5.atlassian.com/browse/jaxb2-commons/collection-setter-injector

Not sure if that could help you as a starting point.

Dan

On Thursday 30 December 2010 5:58:53 pm Jimi HullegÄrd wrote:
> Hi,
> 
> Previously I have used wsdl2java with no binding configuration, and the
> generated classes has been working fine. But when I now added more
> functionallity to the webservice I noticed that the generated List fields
> wasn't proper javabean properties (since they lacked a setter method), and
> that didn't work well together with Apache Commons BeanUtilsBean. The
> result was that all List fields were silently ignored when I used the
> copyProperties method (so I don't have to manually copy all properties
> from the generated class into my own java beans).
> 
> Then I noticed that I can use a binding file, and set
> collectionType="indexed" in the globalBindings-tag, and thereby make
> CXF/JAXB generate classes with array fields, and they are proper javabean
> fields, with a getter and a setter method.
> 
> BUT... now I noticed that the generated setter method has no null-check.
> The first thing it does is:
> 
>    int len = values.length;
> 
> ...and that ofcourse causes a NPE if the array is null, something that is
> not that uncommon. And one would think that the setter method supports
> null, since the wsdl schema specifically states nillable="true" for the
> field, in the complexType definition.
> 
> Is there a specific reason for not having a null-check here? Why not simply
> do like this:
> 
>     if (values == null) {
>         this.myArrayField = null;
>     } else {
>         int len = values.length;
>         ....
> 
> Does anyone know? Maybe this is some setting one can provide in the binding
> file to fix this? Or is this a known bug?
> 
> Regards
> /Jimi

-- 
Daniel Kulp
[email protected]
http://dankulp.com/blog

Reply via email to