Search code examples
javaweb-servicesjspsoapjax-ws

JAX-WS Soap converts String... to List<String>


I am creating a WebService in Java using JAXWS
I have the following interface webmethod:

@WebMethod
public boolean check(String... p);

When i build and run the project, this is what the web service reference function looks like:

public boolean check(
    @WebParam(name = "arg0", targetNamespace = "")
    List<String> arg0)
    throws IllegalAccessException_Exception,
           InvocationTargetException_Exception,
            NoSuchMethodException_Exception;

The String... got replaced with List<String>
Now my question is:

How do i prevent JAXWS from converting my parameters from String... to List<String>


Solution

  • String... (varargs) are basically arrays internally, the only difference is the code that you call it with. Like in main method, you can write main(String... args) instead of main(String[] args).

    JAX-WS uses generics, so that's why it converts your vararg parameter to list, since it's just a normal array.

    If you really want to use array (vararg) parameter then you will need to write your own adapter and annotate the paramter with @XmlJavaTypeAdapter(YourAdapter.class) where YourAdapter extends the XmlAdapter<List<String>, String[]> and overrides both marshall and unmarshall methods. I'm not sure if this will work with parameter (only remember it working with return value), you would have to test it, but I suggest just staying with list parameter.