Skip to content
Advertisement

Spring boot app stops with UnknownContentTypeException when trying to return JSON response from endpoint

I am trying to make a Spring boot app that uses the API endpoints of SWAPI and refine the results to some of them. To explain better I want to take the name of a character the user provided from a GET request and return to him the Starships this character has piloted. I am trying to use RestTemplate to make the calls to the SWAPI API and the refine these results to provide the ones I want. From the debugging I did there seems to be a problem when calling the resttemplate in the for loop in the controller class resulting to this :

JavaScript

Main method

JavaScript

Controller

JavaScript

All entities (InitialResponse, Character, Starship) were created using jsonschema2pojo. I cannot provide the whole classes due to the character limit of the question.

P.S. I am very new and trying to improve the quality of my questions on stack overflow. If I have made mistakes on the format of my question, feel free to provide feedback on this matter aswell.

Advertisement

Answer

After many hours of debugging the issue was at the second restTemplate call in the nested for loop. The url for the call was “http” (e.g. http://swapi.dev/api/starships/12/) and not “https” so it was failing to get the response even though the link works normally in a browser as it automatically redirects to the “https” version. Fixed with the following:

JavaScript
Advertisement