当前位置: 代码迷 >> 综合 >> restTemplate getForEntity 收到 xml
  详细解决方案

restTemplate getForEntity 收到 xml

热度:56   发布时间:2023-09-27 15:56:35.0

Eureka 2.2.3 后,似乎 restTemplate.getForEntity 时默认将接收到的 json 转为 xml

可以使用 exchange 并指定 reponseType

HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<Object> entityForGet = new HttpEntity<>(null, headers);restTemplate.exchange(url, HttpMethod.GET, entityForGet, User.class).getBody();
  相关解决方案