I have attempted to create a simple web service that when called is supposed to return a String array, yet it does not seem to do so and i cannot figure out why?
This WebService is like so:
@WebService
public String[] getData(String testParam)
{
String[] testArray= null;
....//DOES SOMETHING TO TEST PARAM//.....
testArray= longtestString.split("-");
return testArray;
}
Now i create a client that attempts to call this function and recieve a String array back, the code for the client is:
myjaxpackage.GetDataService service = new myjaxpackage.GetDataService();
myjaxpackage.GetData port = service.getGetDataPort();
String testParameter= "this-is-a-test-string";
String[] result = port.getData(testParameter); //Incompatible Types???
Yet the ide (Netbeans) is giving me the error stating that they are incompatible types:
incompatible types
required: java.lang.String[]
found: java.util.List
Would anyone know why this code is not correct, the function is supposed to return a string array and it is being called and fed into one so i dont see how they can be incompatible?
Thanks for any help in the matter.
解决方案
The default binding used here is JAXB - the default mapping of a sequence is a List, so when unmarshalling, JAXB is transforming the sequence in response, to a list which is not compatible with String[]. You have two workarounds:
To change the signature to something which is compatible with JAXB, which will be List
Use XMLJavaTypeAdapter to indicate you would like the types to be adapted - to convert the List to Array before returning - see link to javadoc