1 回答
TA贡献1874条经验 获得超12个赞
问题是您的JSON如下所示:
{
"response": {
...
},
"relatorios": [
{
...
}
]
}
您正在尝试将其直接映射到relatorios列表。您应该RestResponse改为创建另一个对象。这应该包含整个JSON响应内容:
public class RestResponse {
private MyResponse response;
private List<RelatorioResponse> relatorios;
// getter and setter
}
该response对象应代表responseJSON中的部分。如果不需要,也可以添加@JsonIgnoreProperties(ignoreUnknown = true)到RestResponse类中并忽略response属性:
@JsonIgnoreProperties(ignoreUnknown = true)
public static class RestResponse {
private List<RelatorioResponse> relatorios;
// getter and setter
}
您的请求代码应如下所示:
HttpEntity<String> entity = new HttpEntity<>("parameters", new HttpHeaders());
ResponseEntity<RestResponse> response = new RestTemplate().exchange(targetUrl, HttpMethod.GET, entity, RestResponse.class);
List<RelatorioResponse> responses = response.getBody().getRelatorios();
- 1 回答
- 0 关注
- 329 浏览
添加回答
举报