gpt4 book ai didi

java - 从 JAX_WS Web 服务返回对象集合

转载 作者:行者123 更新时间:2023-12-01 14:58:00 25 4
gpt4 key购买 nike

在我的网络服务中,我想根据客户端请求返回对象集合,例如(字符串集合、自定义类..),我的代码:

@XmlRootElement(name="ResultObject")
public class ResultObject
{
private Object _Contents; // this object should contain the collection
private int _ErrorCode;

.....
}

但是当尝试返回 ArrayList 或字符串数​​组时,会出现以下异常:

Dec 30, 2012 5:49:21 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate doGet SEVERE: caught throwable javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context.] at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:322) at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142) at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108) at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:265) at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:320) at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93) at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454) at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244) at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135) at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129) at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160) at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

在搜索解决方案后,一些帖子建议使用注释,但 _Contents 对象是动态集合,我无法修复它的内容。

请指教,谢谢。

最佳答案

_Contents 成员需要 @XmlAnyElement注释,但我对此不太熟悉。也许这篇文章会对您有所帮助:Using @XmlAnyElement to Build a Generic Message

关于java - 从 JAX_WS Web 服务返回对象集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14093677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com