我嘗試輸出documemts的一些列表從資源:編組名單<T>與新澤西州和JAXB
@GET
@Produces({MediaType.APPLICATION_XML})
public Response getDocuments(@QueryParam("provider") String provider) {
List<Document> documents = service.getDocuments(provider);
return Response.ok(
new GenericEntity<List<Document>>(
new ArrayList<Document>(documents)) {})
.build();
}
文檔類不與@XmlElement註釋(我真的不喜歡我的註釋對象很好用這樣的低層次的東西...),但我有一個註冊商爲它:
@Service
@Provider
@Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.WILDCARD})
@Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.WILDCARD})
public class JaxRsDocumentSerializer extends
AbstractMessageReaderWriterProvider<Document> {
當我打電話使用的客戶端與下面的代碼此資源:
return getResource().path("/documents")
.queryParam("provider", provider)
.accept(MediaType.APPLICATION_XML).get(new GenericType<List<Document>>() {});
我得到了可怕的例外:
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException:
A message body writer for Java class java.util.ArrayList, and Java type
java.util.List<com.polyspot.model.core.Document>,
and MIME media type application/xml was not found
我不明白什麼是錯這裏我也跟着代碼,我發現其他地方,包括SO。
非常感謝。
你能否提供任何關於class Document的信息?是否正確註釋? – 2012-03-28 13:06:24
對不起。是的。我們一直在使用Jersey對「年齡」進行編組/解組文檔實例。 – insitu 2012-03-28 15:46:57
Oups。上面的評論是不正確的,我們不註釋對象,但使用自定義提供程序。我更新了這個問題來反映這一點。 – insitu 2012-03-28 15:52:42