无法从 JAX-WS Web 服务返回集合或数组
我发现我无法从 JAX-WS Web 服务返回集合。
我意识到 Java Collections API 可能并不被所有客户端支持,所以我转而返回一个数组,但我似乎也无法做到这一点。
我的 Web 服务设置如下:
@WebService
public class MyClass {
public ReturnClass[] getArrayOfStuff() {
// extremely complex business logic... or not
return new ReturnClass[] {new ReturnClass(), new ReturnClass()};
}
}
ReturnClass 只是一个 POJO。我创建了另一个返回单个实例的方法,并且该方法有效。当我使用集合/数组时,这似乎是一个问题。
当我部署该服务时,在使用它时出现以下异常:
javax.xml.bind.MarshalException - 带有链接异常: [javax.xml.bind.JAXBException:[LReturnClass;在此上下文中未知]
我是否需要以某种方式注释 ReturnClass 类以使 JAX-WS 意识到它? 还是我做错了什么?
I found that I was unable to return collections from my JAX-WS Web Service.
I appreciate that the Java Collections API may not be supported by all clients, so I switched to return an array, but I can't seem to do this either.
I've set up my web service as follows:
@WebService
public class MyClass {
public ReturnClass[] getArrayOfStuff() {
// extremely complex business logic... or not
return new ReturnClass[] {new ReturnClass(), new ReturnClass()};
}
}
And the ReturnClass is just a POJO. I created another method that returns a single instance, and that works. It just seems to be a problem when I use collections/arrays.
When I deploy the service, I get the following exception when I use it:
javax.xml.bind.MarshalException - with linked exception:
[javax.xml.bind.JAXBException: [LReturnClass; is not known to this context]
Do I need to annotate the ReturnClass class somehow to make JAX-WS aware of it?
Or have I done something else wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是正确的方法,但在一种情况下,我想返回一个集合,我将集合包装在另一个类中:
然后:
免责声明:我面前没有实际的代码,所以我想我的示例缺少一些注释等,但这就是要点。
I am unsure of wheter this is the correct way to do it, but in one case where I wanted to return a collection I wrapped the collection inside another class:
And then:
Disclaimer: I don't have the actual code in front of me, so I guess my example lacks some annotations or the like, but that's the gist of it.