Spring restTemplate get raw json string Spring restTemplate get raw json string json json

Spring restTemplate get raw json string


You don't even need ResponseEntitys! Just use getForObject with a String.class like:

final RestTemplate restTemplate = new RestTemplate();final String response = restTemplate.getForObject("https://httpbin.org/ip", String.class);System.out.println(response);

It will print something like:

{  "origin": "1.2.3.4"}