2012-05-14 51 views
0

嘗試從REST服務獲取實體。我的代碼是這樣的:getEntity與GenericType

我想在這樣一個對象發送:new GenericType<List<MyObject>>() {}

到這樣的梅索德:

public static Object callRestWithUrl(String url, Class<?> responseObject) 
      throws MetaServiceException { 

     ClientResponse response = RESTConnectionUtils.callMetaService(url); 

      result = response.getEntity(responseObject); 

     ..... 

但它能夠評估在運行時列表中而不GenericType和拋出異常。

回答

4

你如何調用你的callRestWithUrl方法?

這可能是因爲它會更好地工作,如果你的方法有簽名:

public static Object callRestWithUrl(String url, GenericType<List<?>> responseObject) 

這則調用它,因爲這:

List<...> list = callRestWithUrl(new GenericType<List<MyObject>>() {}); 

也許這個網頁可以幫助: http://persistentdesigns.com/wp/2009/10/jersey-rest-client/

0

由於某種原因,它開始按原樣工作。不知道爲什麼。該方法的輸入需要是通用的。

相關問題