Return ArrayList from WebService in Java

I have a problem returning ArrayList from Web Service (Java)

I have written a test web service and client that consumes it All of this works - that is, the client is calling the server and the server receives an operation request

However, I wrote a simple method that I want to return an ArrayList

My interface is defined as follows:

@WebService
@SOAPBinding(style = Style.RPC)
public interface IsqlServerConnectionWS {

    @WebMethod
    ArrayList getSimpleArrayList();
}

I have my server-side implementation to return ArrayList:

@WebService(endpointInterface="WebServices.IsqlServerConnectionWS")
public class sqlConnectionWSServer
    implements IsqlServerConnectionWS {

    @Override
    public ArrayList getSimpleArrayList() {
        ArrayList al = new ArrayList();
        al.add( "This" );
        al.add( "is" );
        al.add( "a" );
        al.add( "test" );
        return al;
    }
}

Finally, my customer called:

ArrayList results = server.getSimpleArrayList();

The server populates the array list However, on the client side, ArrayList is empty Its size is 0

If I'm in my URL( http://127.0.0.1:9876/myservice -sql? WSDL) checks the WSDL of executeselectsql, which looks like:

<message name="executeSelectsqlResponse">
    <part name="return" type="tns:arrayList"/>
</message>

Did I miss anything?

Edit:

However, if I define a web method in the interface:

@WebMethod
String getAString();

And server implementation:

@Override
public String getAString() {
    return "hello there";
}

So it's good to do this - receive a "hello" on the client

Solution

Use arrays instead of ArrayLists because JAXB cannot treat collections as top-level objects, just as bean properties Alternatively, create a bean and put ArrayList in it

Viewing error: jaxb-223: JAXB doesn't support collection classes as top level objects

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>