Disable List Using Jackson

I have a JSON object:

{"geonames":[
   {"countryId":"2017370",
    "adminCode1":"73"},
   {"countryId":"2027370",
    "adminCode1":"71"},
    ...]}

How can I deserialize this object DIRECTLY List<GeoName> , ignoring the first layer (geonames wrapper) instead of deserializing it to a wrapper containing List<GeoName>how @JsonProperty("geonames")?

+4
source share
1 answer

Use ObjectReaderwith root name

ObjectMapper mapper = new ObjectMapper();
ObjectReader reader = mapper.reader(new TypeReference<List<GeoName>>() {}).withRootName("geonames");
List<GeoName> list = reader.readValue(json);
+2
source

Source: https://habr.com/ru/post/1569383/


All Articles