-1
I am trying to consume the themoviedb webservice and am encountering 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": the false, "backdrop_path": "/Auxc0sspzaafddtsmnxsnbeeejr.jpg", "belongs_to_collection": null, "budget": 2000000, "sons-in-law": [ { "id": 18, "name": "Drama" }, { "id": 53, "name": "Thriller" } ], "homepage": null, "id": 55, "imdb_id": "tt0245712", "original_language": "es", "original_title": "Loves 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; an injured Supermodel’s designer Pooch disappears into the Apartment’s floorboards; 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": "es", "name": "Español" } ], "status": "Released", "tagline": "Love. Betrayal. Death." "title": "Loves Perros", "video": false, "vote_average": 7.7, "vote_count": 855 }
There was an Unexpected error (type=Internal Server Error, status=500). Error while extracting [java.util.List] and content type [application/json;charset=utf-8]; nested Exception is org.springframework.http.converter.Httpmessagenotreadableexception: JSON parse error: Cannot deserialize instance of
java.util.ArrayList
out of START_OBJECT token; nested Exception is com.fasterxml.Jackson.databind.exc.Mismatchedinputexception: Cannot 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 Sponse for type [java.util.List] and content type [application/json;charset=utf-8]; nested Exception is org.springframework.http.converter.Httpmessagenotreadableexception: JSON parse error: Cannot deserialize instance ofjava.util.ArrayList
out of START_OBJECT token; nested Exception is com.fasterxml.Jackson.databind.exc.Mismatchedinputexception: Cannot deserialize instance ofjava.util.ArrayList
out of START_OBJECT token at [Source: (Pushbackinputstream); line: 1, column: 1]
@Robson if possible also post the return service JSON
– nullptr
I ended up doing a mix because I was working on two projects (beginner). Json can be found at https://api.themoviedb.org/3/movie/55?api_key=8a39fa19e513b70d41402ac67813ae35
– Robson Silva
Anyway, you’re only getting a Movie on JSON and deserializing a list.
– nullptr
Change the code to consider only Movie, and try again
– nullptr
I changed the url to receive a list of movies, and it returns the same error. "https://api.themoviedb.org/3/movie/popular?api_key=8a39fa19e513b70d41402ac67813ae35" It is as if api_key was not passed by restTemplate.
– Robson Silva
I mapped Json with http://www.jsonschema2pojo.org/ to generate the POJO, generating all classes involved, but I was not successful.
– Robson Silva