Does JAXWS client make difference between an empty collection and a null collection value as returne

Posted by snowflake on Stack Overflow See other posts from Stack Overflow or by snowflake
Published on 2010-02-12T08:41:51Z Indexed on 2010/05/16 2:10 UTC
Read the original article Hit count: 355

Filed under:
|
|
|

Since JAX-WS rely on JAXB, and since I observed the code that unpack the XML bean in JAX-B Reference Implementation, I guess the difference is not made and that a JAXWS client always return an empty collection, even the webservice result was a null element:

public T startPacking(BeanT bean, Accessor<BeanT, T> acc) throws AccessorException {
        T collection = acc.get(bean);
        if(collection==null) {
            collection = ClassFactory.create(implClass);
            if(!acc.isAdapted())
                acc.set(bean,collection);
        }
        collection.clear();
        return collection;
    }

I agree that for best interoperability service contracts should be non ambiguous and avoid such differences, but it seems that the JAX-WS service I'm invoking (hosted on a Jboss server with Jbossws implementation) is returning as expected either null either empty collection (tested with SoapUI).

I used for my test code generated by wsimport. Return element is defined as:

@XmlElement(name = "return", nillable = true)
protected List<String> _return;

I even tested to change the Response class getReturn method from :

public List<String> getReturn() {
    if (_return == null) {
        _return = new ArrayList<String>();
    }
    return this._return;
}

to

public List<String> getReturn() {
    return this._return;
}

but without success.

Any helpful information/comment regarding this problem is welcome !

© Stack Overflow or respective owner

Related posts about jax-ws

Related posts about Xml