Hi,

thank your for your answer. I have tried your workarounf but it does not 
work. Here is my Interface:

        @WebMethod(action = "leseObligoKunde", operationName = 
"leseObligoKunde")
        @ResponseWrapper(className="ObligoKontoListResponse")
        public List<ObligoKonto> leseObligoKunde(KordobaCredentials creds,
                        String kundennummer) throws KordobaException


and this is my ResponseWrapper:

@XmlType(name = "ObligoKontoListResponse")
public class ObligoKontoListResponse {
 
        @XmlElementWrapper(nillable = true, name = "return")
        @XmlElement(name = "obligoKontoList")
        public List<ObligoKonto> obligoKontoList;
}

If I trace the response with tcpmon I can see that there is now an 
explicit return value:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Content-Length: 309
Date: Thu, 14 Jan 2010 16:14:42 GMT

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/
"><soap:Body><ns2:leseObligoKundeResponse xmlns:ns2="
http://kordoba5/ObligoWebService/1/";><return xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"; 
xsi:nil="true"/></ns2:leseObligoKundeResponse></soap:Body></soap:Envelope>
 
But on the client I get again a NullPointerException:

        List<ObligoKonto> erg = obligoService.leseObligoKunde(creds, 
"0000186040");
        System.out.println(erg.size());


Then I made another test and removed the @ResponseWrapper Annotation of 
the Web Service on client side. Now my result contains one element, but 
with empty properties. 

What I am doing wrong?

Thanks,
Marc






Von:
Daniel Kulp <[email protected]>
An:
[email protected]
Kopie:
[email protected]
Datum:
13.01.2010 16:53
Betreff:
Re: Returntype List: Empty List get null on client?



On Wed January 13 2010 4:51:17 am [email protected] wrote:
> Hello,
> 
> I have a problem with the return type of a web service function:
> 
> public List<Customer> findCustomer(String name);
> 
> If my service returns a empty list, the list get null on the client. Is
> this a bug? Is there any workaround? Do I have to use Arrays instead of
> Lists?

Not really a bug.   It's more due to how the spec maps the List into 
schema 
and thus the representation on the wire.   It would map that list to 
something 
like:

<element name="return"  type="tns:customer" 
      maxOccurs="unbounded" minOccurs="1"/>

Thus, if the list is empty or if the list is null, no "return" element is 
put 
on the wire at all.   On the receiving side, the runtime really has no 
indication of whether it should be an empty list or a null list. 

I think the only way around it would be to create a new bean like:

@XmlType(name = "findCustomerResponse")
public class FindCustomerResponse {
    @XmlElementWrapper(nillable = true, name="return")
    @XmlElement(name = "customers")
    List<Customer> customers;

    ......getter/setters.....
}

and then add an annotation to the method:
 @ResponseWrapper(class = "......FindCustomerResponse")
 public List<Customer> findCustomer(String name);

That changes the schema a bit to create a single "return" element that is 
nillable that then wrappers the "customer" elements.



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

Reply via email to