2012-08-06 77 views
1

我有這樣的資源:Jersey客戶端的java.util.List <POJO>自動轉換器

@GET 
@Path("/todos") 
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) 
public List<Cliente> getListagem() { 

而且我的球衣的客戶是:

ClientResponse response1 = wr.accept(MediaType.APPLICATION_XML).get(ClientResponse.class); 
List<Cliente> colecao = response1.getEntity(List.class); 

它產生的誤差修改 墓:消息正文Java類java.util.List和Java類型接口java.util.List,MIME媒體類型application/xml未找到

我想知道爲什麼球衣成爲XML中的列表並且客戶端無法自動轉換它? 解決這個問題的最佳方法是什麼? 問候..

回答

3

試試這個服務器上:

public JResponse<List<Cliente>> getListagem() { 
    List<Cliente> response = ......; 
    return JResponse.ok(response).build(); 
} 

這在客戶端上:

Client client = Client.create(); 
WebResource resource = client.resource("http://localhost:8080/service"); 
List<Cliente> colecao = resource.accept(MediaType.APPLICATION_XML).get(new GenericType<List<Cliente>>() {}); 
+0

如何將客戶端來獲取上市? – 2012-08-07 13:06:30

+0

添加客戶端代碼到答案... – condit 2012-08-07 15:10:03

+0

好的.....我會試試.. – 2012-08-07 19:13:19