Could not read JSON: Can not deserialize instance of hello.Country[] out of START_OBJECT token
You need to do the following:
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();
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)
Another solution:
public class CountryInfoResponse { private List<Object> geonames;}
Usage of a generic Object-List solved my problem, as there were other Datatypes like Boolean too.
In my case, I was getting value of <input type="text">
with JQuery and I did it like this:
var newUserInfo = { "lastName": inputLastName[0].value, "userName": inputUsername[0].value, "firstName": inputFirstName[0] , "email": inputEmail[0].value}
And I was constantly getting this exception
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: java.io.PushbackInputStream@39cb6c98; line: 1, column: 54] (through reference chain: com.springboot.domain.User["firstName"]).
And I banged my head for like an hour until I realised that I forgot to write .value
after this"firstName": inputFirstName[0]
.
So, the correct solution was:
var newUserInfo = { "lastName": inputLastName[0].value, "userName": inputUsername[0].value, "firstName": inputFirstName[0].value , "email": inputEmail[0].value}
I came here because I had this problem and I hope I save someone else hours of misery.
Cheers :)