I'm trying to consume the themoviedb webservice and am encountering the following error.
----------------------- POJO ----------------------- - package com.wsemovie.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Movie {
public String adult;
public String budget;
public String original_language;
public String original_title;
public String overview;
public String title;
public Movie() {
super();
}
public String getAdult() {
return adult;
}
public void setAdult(String adult) {
this.adult = adult;
}
public String getBudget() {
return budget;
}
public void setBudget(String budget) {
this.budget = budget;
}
public String getOriginal_language() {
return original_language;
}
public void setOriginal_language(String original_language) {
this.original_language = original_language;
}
public String getOriginal_title() {
return original_title;
}
public void setOriginal_title(String original_title) {
this.original_title = original_title;
}
public String getOverview() {
return overview;
}
public void setOverview(String overview) {
this.overview = overview;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
-------------- Controller ---------------------
@Controller
public class MovieController {
@GetMapping("/")
@ResponseBody
public String movies(Model model ) {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<List<Movie>> resposne =
restTemplate.exchange(
"https://api.themoviedb.org/3/movie/55?api_key=8a39fa19e513b70d41402ac67813ae35",
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Movie>>() { }
);
List<Movie> lista = resposne.getBody();
model.addAttribute("lista", lista);
return "movie"; //Invocando o template thymeleaf
}
}
---------------------- JSON ------------------------ -----------
{ "adult": false, "backdrop_path": "/AuXC0SsPZaAfddtSMnxSnbEeEjR.jpg", "belongs_to_collection": null, "budget": 2000000, "genres": [ { "id": 18, "name": "Drama" }, { "id": 53, "name": "Thriller" } ], "homepage": null, "id": 55, "imdb_id": "tt0245712", "original_language": "is", "original_title": "Amores perros", "overview": "Three different people in Mexico City are catapulted into dramatic and unforeseen circumstances in the wake of a terrible car crash: a young punk stumbles into the sinister underground world of dog fighting; ; and an ex-radical turned hit man rescues a gunshot Rotweiler. ", "popularity": 5,686, "poster_path": "/8gEXmIzw1tDnBfOaCFPimkNIkmm.jpg", "production_companies": [ { "id": 5084, "logo_path": null, "name": "Altavista Films", "origin_country": "" }, { "id": 11230, "logo_path": null, "name": "Zeta Film", "origin_country": "" } ], "production_countries": [ { "iso_3166_1": "MX", "name": "Mexico" } ], "release_date": "2000-06-16", "revenue": 20908467, "runtime": 154, "spoken_languages": [ { "iso_639_1": "is", "name": "Spanish" } ], "status": "Released", "tagline": "Love. Betrayal. Death.", "title": "Amores Perros", "video": false, "vote_average": 7.7, "vote_count": 855 }
There was an unexpected error (type = Internal Server Error, status = 500). Error while extracting response for type [java.util.List] and content type [application / json; charset = utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of
java.util.ArrayList
out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance ofjava.util.ArrayList
out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1] org.springframework.web.client.RestClientException: Error while extracting response for type [java.util.List] and content type [application / json; charset = utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance ofjava.util.ArrayList
out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance ofjava.util.ArrayList
out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]