如何从spring rest模板中获取原始json字符串?我已经尝试了下面的代码,但它返回给我json没有引号导致其他问题,我怎么能得到json原样。
// helper recursive method to "flatten" the schema:
def getFields(parent: String, schema: StructType): Seq[String] = schema.fields.flatMap {
case StructField(name, t: StructType, _, _) => getFields(parent + name + ".", t)
case StructField(name, _, _, _) => Seq(s"$parent$name")
}
// apply to our DF's schema:
val fields: Seq[String] = getFields("", df.schema)
// select these fields:
val result = df.select(fields.map(name => $"$name" as name): _*)
答案 0 :(得分:25)
你甚至不需要ResponseEntity
!只需将getForObject
与String.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"
}