users@glassfish.java.net

Q: JAX-WS based webservice always returns empty collection instead of null?

From: <glassfish_at_javadesktop.org>
Date: Fri, 09 Nov 2007 11:52:56 PST

Using JAX-WS RI 2.1.1-b03, I coded up a simple web service like this:

package com.mycompany.samples;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;

@WebService(name="SampleServer", targetNamespace="http://samples.mycompany.com/", serviceName="SampleService")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL)
public class SampleService {

        /**
         * Return null List
         */
        @WebMethod(operationName="getNullList", action="urn:getNullList")
        @WebResult(name="List")
        public List getNullList() {
                return null;
        }

        /**
         * Return null object
         */
        @WebMethod(operationName="getNullObject", action="urn:getNullObject")
        @WebResult(name="Object")
        public Object getNullObject() {
                return null;
        }
}

I used wsgen to generate server/client sides class, then deploy the server code to Tomcat.

I wrote a simple client app to access this web services, and noticed that the getNullList() call always returns an empty list instead of null, and the getNullObject() always returns null.

Why the null return value on the server side was marshaled into an empty list on the client side? Is this a bug? Are there any means to work around this?

Thanks.
[Message sent by forum member 'pyou1508' (pyou1508)]

http://forums.java.net/jive/thread.jspa?messageID=244816