Could not read JSON: Can not deserialize instance of hello.Country[] out of START_OBJECT token

前端 未结 5 1151
攒了一身酷
攒了一身酷 2020-12-13 18:05

I have rest url that gives me all countries - http://api.geonames.org/countryInfoJSON?username=volodiaL.

I use RestTemplate from spring 3 to parse returned json into

5条回答
  •  鱼传尺愫
    2020-12-13 18:26

    If you want to avoid using an extra Class and List genomes you could simply use a Map.

    The data structure translates into Map>

    String resourceEndpoint = "http://api.geonames.org/countryInfoJSON?username=volodiaL";
    
    Map> geonames = restTemplate.getForObject(resourceEndpoint, Map.class);
    
    List countries = geonames.get("geonames");
    

    提交回复
    热议问题