使用postForObject方法遠程調用接口,正常會返回List<HashMap>,然而實際上卻返回List<LinkedHashMap>,同時將此數據進行json轉換,變成了帶有反斜杠的json格式數據
List<Map<String, String>> list = restTemplate.postForObject(url, params, List.class);
解決方案:
反斜杠:rest請求接口返回類型改為Object
Map類型錯誤:
使用此方法指定泛型,正確接收數據,再進行json轉換
ParameterizedTypeReference<List<HashMap>> typeRef = new ParameterizedTypeReference<List<HashMap>>() {};
ResponseEntity<List<HashMap>> responseEntity = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(params), typeRef);
List<HashMap> list = responseEntity.getBody();