使用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();
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2021-09-10
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2021-10-02
  • 2021-05-26
相关资源
相似解决方案