1
我們在我們的應用程序的commons軟件包中使用restemplate。所以我們需要使用泛型類型。RestTemplate:如何獲得泛型列表響應
我瞭解,很多解決方案,但沒有一個似乎不爲我們工作,我們不斷地得到(在客戶端):
java.util.LinkedHashMap cannot be cast to nc.gouv.dsf.ranch.model.Pays
下面是代碼(總結):
public List<T> findAll(C criteria) {
[...]
ResponseEntity<List<T>> response =
restTemplateFactory.getRestTemplate().exchange(
url,
HttpMethod.GET,
new HttpEntity<>(createHttpHeaders(srvId)),
new ParameterizedTypeReference<List<T>>() {}
);
return response.getBody();
}
我雖然ParameterizedTypeReference什麼解決這種問題,但它不起作用。
PS:我們正在使用springboot 1.3.1.RELEASE
不工作之一:「org.springframework.http.converter.HttpMessageNotReadableException:無法讀取文件:在無法反序列化java.util.LinkedHashMap中的實例進行START_ARRAY令牌 的[來源:[email protected]; line:1,column:1];嵌套異常是com.fasterxml.jackson.databind.JsonMappingException:無法將java.util.LinkedHashMap的實例反序列化爲START_ARRAY標記「並且我也鬆散通用類型與Object的優點。 – Tyvain
您可以添加有問題的示例回覆嗎? –
請將示例JSON有效負載和更多數據添加到問題中。 –