在尝试调用并解析JSON响应时,遇到了问题。
[
{
"name": "john doe",
"age": "24",
"address": "{\"state\":\"LA\",\"country\":\"US\"}"
}
]
Models:
Person.java
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Person {
private String name;
private String age;
private Address address;
}
地址.java
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Address {
private String state;
private String country;
}
代码读取这些数据:
ResponseEntity<List<Person>> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,requestEntity,new ParameterizedTypeReference<List<Person>>() {});
但是我收到以下异常:
调用ABS服务时出现RestClientException错误,提取类型为
[java.util.List<com.bp.model.Person>]
和内容类型[application/json;charset=UTF-8]的响应时发生ServiceError;嵌套异常为org.springframework.http.converter.HttpMessageNotReadableException:JSON解析错误:无法构造com.bp.model.Address
实例(尽管至少存在一个创建者):没有String参数构造函数/工厂方法从字符串值('{"state":"LA","country":"US"}')反序列化;嵌套异常为com.fasterxml.jackson.databind.exc.MismatchedInputException:无法构造com.bp.model.Address
实例(尽管至少存在一个创建者):没有String参数构造函数/工厂方法从字符串值('{"state":"IN","brand":"anthem"}')反序列化 在[来源:(PushbackInputStream);行:1,列:325](通过引用链:java.util.ArrayList [0] -> com.bp.model.Person ["address"])