org.springframework.web.client.RestClientException: Error while extracting response for type [class com.radar.dto.WorldDTO] and content type [application/json;charset=UTF-8];
nested exception is org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot deserialize instance of `com.radar.dto.WorldDTO` out of START_ARRAY token;
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.radar.dto.WorldDTO` out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 1]
我正在尝试获取的JSON格式:
[
{
"id": "110",
"name": "England",
"areas": [
{
"id": "1620",
"name": "London"
},
...
]
},
...
]
dto类:
@Data
public class WorldDTO {
private List<CountryDTO> countries;
}
@Data
private static class CountryDTO {
@JsonProperty(value = "id")
private String id;
@JsonProperty(value = "name")
private String name;
@JsonProperty(value = "areas")
private List<AreaDTO> areas;
}
@Data
public class AreaDTO {
@JsonProperty(value = "id")
private String id;
@JsonProperty(value = "name")
private String name;
}
我调用API的一段代码:
RequestEntity<?> request = new RequestEntity<>(HttpMethod.GET, uri);
ResponseEntity<WorldDTO> response = restTemplate.exchange(request, new ParameterizedTypeReference<>() {});
WorldDTO dto = response.getBody();
List countries;@JsonProperty
我究竟做错了什么?