1

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<java.lang.String>

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.

Des C
  • 61
  • 2
  • 4

2 Answers2

1

The type that shows up on the client is not necessarily going to be the same as the server. The two don't even have to be the same programming language. It's all converted to and from XML and each side is free to convert its native structures into and out of XML however it wants.

JOTN
  • 6,120
  • 2
  • 26
  • 31
1

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:

  1. To change the signature to something which is compatible with JAXB, which will be List<String>

  2. Use XMLJavaTypeAdapter to indicate you would like the types to be adapted - to convert the List to Array before returning - see link to javadoc

Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125