Java SpringRESTTemplate获取原始json字符串

Java SpringRESTTemplate获取原始json字符串,java,json,spring,spring-mvc,spring-rest,Java,Json,Spring,Spring Mvc,Spring Rest,如何从SpringREST模板获取原始json字符串?我尝试了以下代码,但它返回的json没有引号,这会导致其他问题,我如何才能获得json的原样 ResponseEntity<Object> response = restTemplate.getForEntity(url, Object.class); String json = response.getBody().toString(); ResponseEntity response=restemplate.getForE

如何从SpringREST模板获取原始json字符串?我尝试了以下代码,但它返回的json没有引号,这会导致其他问题,我如何才能获得json的原样

ResponseEntity<Object> response  = restTemplate.getForEntity(url, Object.class);
String json = response.getBody().toString();
ResponseEntity response=restemplate.getForEntity(url,Object.class);
字符串json=response.getBody().toString();

您甚至不需要
响应!只需与
字符串一起使用即可。class
类似:

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

System.out.println(response);
它将打印如下内容:

{
  "origin": "1.2.3.4"
}

你能把示例打印出来吗?你试过使用
字符串吗<代码>restTemplate.getForEntity(url,String.class)
我的返回类型是object,我想要原始的json字符串?当服务器发送
应用程序/json
作为内容类型
时,这不会起作用
无法从START\u数组标记中反序列化java.lang.string的实例
如果主体仅包含json字符串,它只会给您一个字符串