Skip to content
Advertisement

RestTemplate parsing from Response entity to an Object

First I created this method to get me a Pokemon by Id and parse it to a POJO class using RestTemplate.

JavaScript

So far everything works fine, but now I have to parse a list of Pokemons and I can’t find a way to do the same thing with a list of objects. I already have the response correct but cant merge it to my POJO. If I change to String as the line that is commented I get the response but not the way I want it using the POJO.

JavaScript

The main goal is to get all the 151 URLs that contain the description from every pokemon and save it in my DB.

Advertisement

Answer

If I understood correctly what you want to achieve, you need to use ParameterizedTypeReference<List<PokemonUrl>>() {} in your restTemplate call so that you can get a list of PokemonUrl as follows:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement