I have problem with parsing json array to java collection of specified objects.
JSON response:
{
"data": [
{
"country_code": "US",
"name": "United States",
"supports_region": "true",
"supports_city": "true"
},
{
"country_code": "CA",
"name": "Canada",
"supports_region": "true",
"supports_city": "true"
},
{
"country_code": "GB",
"name": "United Kingdom",
"supports_region": "true",
"supports_city": "true"
}
]
}
Next I have class of single country:
@JsonIgnoreProperties(ignoreUnknown = true)
public class TargetCountry {
@JsonProperty("country_code")
private String countryCode;
@JsonProperty("name")
private String name;
public String getCountryCode() {
return countryCode;
}
public String getName() {
return name;
}
}
I'm using Jackson library to parse json into java.
Everything would be fine if there won't be extra field "data" which wraps array.
I don't want to make additionally wrapper class due to "data" field. How can I parse that response in elegant way to receive: Collection<TargetCountry>
for example:
RestTemplate restTemplate = new RestTemplate();
TargetCountry[] countryList = restTemplate.getForObject(uri, TargetCountry[].class);