I know this may be simple. However, I just can\'t get it to work.
So I am trying to use Spring RestTemplate to map my JSON data. I have following JSON response from a re
I was having a similar issue with RestTemplate not mapping nested JSON objects to my class model also, after much frustration I decided to retrieve my JSON as a String(instead of converting directly to my target object) using RestTemplate and then use the google Gson library to convert my String to my target entity.
pom.xml
com.google.code.gson
gson
2.2.4
code to call RestTemplate:
ResponseEntity responseEntity = restTemplate.getForEntity(Url,String.class);
Gson gson = new GsonBuilder().create();
Response reponse = gson.fromJson(responseEntity , Response.class);
Unfortunately I was unable to find out why my nested objects were not mapped using RestTemplate the first place but I hope this workaround helps!