2012-06-27 19 views
0

我用this章4.3,在我休息服務的POJO通信。此刻我可以發佈並獲得pojo。它工作正常。但是,當我試圖讓我的迴應的實體中我得到這個異常:澤西 - POJO的通信工程,getEtntity犯規

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(); 

我想它也只包裝的POJO沒有JAXBElement。

在客戶端我嘗試不同的方法:

GenericType<JAXBElement<ObjectPOJO>> objectType = new GenericType<JAXBElement<ObjectPOJO>>() {}; 
objectType = (GenericType<JAXBElement<ObjectPOJO>>) res.getEntity(JAXBElement.class).getValue(); 

object = res.getEntity(ObjectPOJO.class); 

等。有誰知道什麼是正確的方法?就像我說的那樣,即時通信工作正常。

回答

2

它應該是:

ObjectPOJO object = res.getEntity(new GenericType<JAXBElement<ObjectPOJO>>() {}).getValue(); 
+0

感謝隊友,U幫了我很多過去。一個錯誤:它應該是getValue() –

+0

謝謝,我更新了答案。 –