我有一个嵌套的 json pojo,其中 json 的嵌套部分用@JsonRawValue. 我正在尝试使用 rest 模板进行映射,但出现错误 JSON 解析错误:Cannot deserialize instance of java.lang.String out of START_OBJECT token;
嵌套异常是com.fasterxml.jackson.databind.exc.MismatchedInputException.
这是我的响应对象的样子:
import com.fasterxml.jackson.annotation.JsonRawValue;
public class ResponseDTO {
private String Id;
private String text;
@JsonRawValue
private String explanation;
//getters and setters;
}
Run Code Online (Sandbox Code Playgroud)
explanation映射到字符串的 json在哪里。这适用于邮递员,招摇,我在响应中看到解释为 json。
但是当我使用 Rest Template 测试它时:
ResponseEntity<ResponseDTO> resonseEntity = restTemplate.exchange(URI, HttpMethod.POST, requestEntity, ResponseDTO.class);
Run Code Online (Sandbox Code Playgroud)
我看到这个例外:
org.springframework.web.client.RestClientException: Error while extracting
response for type [class com.**.ResponseDTO] and content type
[application/json;charset=utf-8]; nested exception is
org.springframework.http.converter.HttpMessageNotReadableException: JSON
parse …Run Code Online (Sandbox Code Playgroud)