java返回字符数组,使用Java JAX-WS返回字符串数组?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值