我使用4.3章在我的 rest 服务中与 pojos 通信。目前我可以发布并获取pojo。它工作正常。但是,当我尝试获取响应的实体时,我得到了这个异常:
27.06.2012 10:44:44 com.sun.jersey.api.client.ClientResponse getEntity
SCHWERWIEGEND: A message body reader for Java class javax.xml.bind.JAXBElement, and Java type class javax.xml.bind.JAXBElement, and MIME media type application/xml was not found
27.06.2012 10:44:44 com.sun.jersey.api.client.ClientResponse getEntity
SCHWERWIEGEND: The registered message body readers compatible with the MIME media type are:
application/xml ->
在服务器端,我像这样包装实体:
res = Response.created(UriBuilder.fromUri(uriInfo.getAbsolutePath() + "/" + object.getObjectId()).build()).entity(new JAXBElement<ObjectPOJO>(new QName("objectpojo"), ObjectPOJO.class, object)).build();
我也试过了,只是在没有 JAXBElement 的情况下包装 pojo。
在客户端,我尝试了不同的方法:
GenericType<JAXBElement<ObjectPOJO>> objectType = new GenericType<JAXBElement<ObjectPOJO>>() {};
objectType = (GenericType<JAXBElement<ObjectPOJO>>) res.getEntity(JAXBElement.class).getValue();
object = res.getEntity(ObjectPOJO.class);
等等。有谁知道什么是正确的方法?就像我说的,get 和 post 通信工作正常。