简体   繁体   中英

How can I create Java web service (jax-ws) with array or List as a parameter

I've got a problem with a web service which has an array or List as parameter. Here is example:

@WebMethod
public String printList(@WebParam(name = "list") List<String> list) {
    String result = "";
    if(list == null) {
        result = "list is null";
    } else if(list.size() == 0) {
        result = "list is empty";
    } else {
        for(String elem : list) {
            result += elem + " ";
        }
    }
    return result;
}

When I call printList from web service client the result is always "list is empty" The same is when I use array of String. Should I use some additional annotations or something?

Your code is perfect , it seems you are calling it wrong way,

and you can remove second condition directly second else will work

JAX Webservice 中的数组数据类型不支持,所以你需要使用库和工具来做这样的事情......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM