I have a JSON Object like this:
{"geonames":[
{"countryId":"2017370",
"adminCode1":"73"},
{"countryId":"2027370",
"adminCode1":"71"},
...]}
How can i deserialize this object DIRECTLY to List<GeoName>
, ignoring the first layer (geonames wrapper), instead of deserializing to a wrapper object containing List<GeoName>
as @JsonProperty("geonames")
?
Use an ObjectReader
with a root name
ObjectMapper mapper = new ObjectMapper();
ObjectReader reader = mapper.reader(new TypeReference<List<GeoName>>() {}).withRootName("geonames");
List<GeoName> list = reader.readValue(json);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With