[英]JAX-RS Jersey XML <-> java.util.List
I try to access a JAX-RS Web Service which is returning me a java.util.list of Values in XML but I get javax.xml.bind.UnmarshalException in Client-Side... 我尝试访问一个JAX-RS Web服务,该服务以XML返回值的java.util.list,但在客户端出现javax.xml.bind.UnmarshalException ...
Web Service method: Web服务方法:
@GET
@Path("/getMessdaten")
@Produces(MediaType.APPLICATION_XML)
public List<MessdatenPCommon> getMessdatenValues() throws Exception {
List<MessdatenPCommon> messdatenPList = testBean();
return MessdatenPCommonList;}
access code in client: 客户端中的访问代码:
List<MessdatenPCommon> m = webResource.path("test").path("helloworld/getMessdaten").accept(MediaType.APPLICATION_XML).et(new GenericType<List<MessdatenPCommon>>() {});
The Exception in Client: 客户端异常:
Exception in thread "main" javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException
- with linked exception:
[com.sun.istack.internal.SAXParseException2; lineNumber: 1; columnNumber: 89; Unable to create an instance of xx.xxxx.xxx.xxx.xxxxx.xxxx.MessdatenPCommon]
at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.readFrom(AbstractListElementProvider.java:251)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:553)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:523)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
at com.sun.jersey.api.client.WebResource.access$300(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:508)
at appclient.TestClient.main(TestClient.java:31)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[com.sun.istack.internal.SAXParseException2; lineNumber: 1; columnNumber: 89; Unable to create an instance of xx.xxxxx.xxx.xxx.xxxxx.xxxxx.MessdatenPCommon]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown Source)
at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.readFrom(AbstractListElementProvider.java:234)
... 6 more
Caused by: com.sun.istack.internal.SAXParseException2; lineNumber: 1; columnNumber: 89; Unable to create an instance of xx.xxxx.xxx.xxx.xxxx.xxxx.MessdatenPCommon
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(Unknown Source)
....
The MessdatenPCommon class: MessdatenPCommon类:
@XmlSeeAlso({ MessdatenPv.class })
@XmlType
public abstract class MessdatenPCommon extends xx.xxxx.xxx.xxx.AbstractEntityBase {
private static final long serialVersionUID = 1L;
public abstract BigDecimal getNum();
public abstract ...
}
Can anyone help me out? 谁能帮我吗?
Thx! 谢谢!
I am assuming you are expecting to receive an instance of MessdatenPv
which is a subclass of MessdatenPCommon
? 我假设您期望接收到
MessdatenPv
的子类MessdatenPCommon
? This is since MessdatenPCommon
is abstract, and MessdatenPv
is reference in the @XmlSeeAlso
annotation. 这是因为
MessdatenPCommon
是抽象的,而MessdatenPv
是@XmlSeeAlso
批注中的@XmlSeeAlso
。 You will need to ensure that the XML contains the necessary xsi:type
attribute to indicate the subtype. 您将需要确保XML包含必要的
xsi:type
属性以指示子类型。
You can marshal out the data to see what is expected on the unmarshal. 您可以封送数据,以查看对封送的期望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.