且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法读取JSON:无法反序列化START_OBJECT令牌中的hello.Country []实例

更新时间:2022-01-10 17:24:42

您需要执行以下操作:

public class CountryInfoResponse {

   @JsonProperty("geonames")
   private List<Country> countries; 

   //getter - setter
}

RestTemplate restTemplate = new RestTemplate();
List<Country> countries = restTemplate.getForObject("http://api.geonames.org/countryInfoJSON?username=volodiaL",CountryInfoResponse.class).getCountries();

如果您可以使用某种注释来跳过级别会很棒,但它是还不可能(参见这个 this

It would be great if you could use some kind of annotation to allow you to skip levels, but it's not yet possible (see this and this)