I'm using Spring RestTemplate and Jackson 2.1 and I'm trying to deserialise the JSON string below. Whereas the first number is an unique ID so this will be dynamic:
{"2127388":{"name":"John","city":"Amsterdam","country":"The Netherlands"}}
With RestTemplate I do the following:
final ResponseEntity<UserDetailsWrapper> re = restTemplate.getForEntity(apiUrl, UserDetailsWrapper.class);
The POJO's I have are
class UserDetailsWrapper {
private long uniqueId; // [getter + setter]
private UserDetails userDetails; // [getter + setter]
// no args constructor + all properties constructor
}
class UserDetails {
private String name; // [getter + setter]
private String city; // [getter + setter]
private String country; // [getter + setter]
// no args constructor + all properties constructor
}
The UserDetailsWrapper class gets instantiated but all its properties remain null.
When I simply do:
{"name":"John","city":"Amsterdam","country":"The Netherlands"}
I am able to deserialise to the UserDetails class with all properties filled as expected, so my configuration should be in order. Probably I need to have the UserDetailsWrapper class annotated at specific places or I need to have a custom deserialiser. I tried both but to be honest I have no clue what to do precisely.
If someone can help me out with this I will be a happy man again.