c-eg / themoviedbapi

A Java wrapper around the JSON API provided by TheMovieDB.org
https://www.themoviedb.org/
Other
281 stars 95 forks source link

mapJsonResult fails on "belongs_to_collection" parsing #210

Closed RafaelPereiraa closed 6 months ago

RafaelPereiraa commented 6 months ago

When you try to fetch info of some old movies, it works like a charm because all of them returns "null" on the field "belong_to_collection".

e.g. movie 5353, the hunting party (the one from the readme)

{
  "adult": false,
  "backdrop_path": "/cN6GW2y4m7lEuc5t5ahafgAQRbN.jpg",
  "belongs_to_collection": null,
  "budget": 15000000,
  "genres": [
    {
      "id": 28,
      "name": "Action"
    },
    {
      "id": 12,
      "name": "Adventure"
    },
    {
      "id": 53,
      "name": "Thriller"
    },
    {
      "id": 18,
      "name": "Drama"
    }
  ],
  "homepage": "http://www.thehuntingpartymovie.com/",
  "id": 5353,
...
}

But if you try to fetch any newer movies, like Dune 2:

{
  "adult": false,
  "backdrop_path": "/xOMo8BRK7PfcJv9JCnx7s5hj0PX.jpg",
  "belongs_to_collection": {
    "id": 726871,
    "name": "Dune Collection",
    "poster_path": "/wcVafar6Efk3YgFvh8oZQ4yHL6H.jpg",
    "backdrop_path": "/ygVSGv86R0BTOKJIb8RQ1sFxs4q.jpg"
  },
  "budget": 190000000,
  "genres": [
    {
      "id": 878,
      "name": "Science Fiction"
    },
    {
      "id": 12,
      "name": "Adventure"
    }
  ],
  "homepage": "https://www.dunemovie.com",
  "id": 693134
...
}

it does not have a class to map it, resulting in:

java.lang.RuntimeException: info.movito.themoviedbapi.tools.TmdbException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: (String)"{"adult":false,"backdrop_path":"/xOMo8BRK7PfcJv9JCnx7s5hj0PX.jpg","belongs_to_collection":{"id":726871,"name":"Dune Collection","poster_path":"/wcVafar6Efk3YgFvh8oZQ4yHL6H.jpg","backdrop_path":"/ygVSGv86R0BTOKJIb8RQ1sFxs4q.jpg"},"budget":190000000,"genres":[{"id":878,"name":"Science Fiction"},{"id":12,"name":"Adventure"}],"homepage":"https://www.dunemovie.com","id":693134,"imdb_id":"tt15239678","origin_country":["US"],"original_language":"en","original_title":"Dune: Part Two","overview":"Follow "[truncated 859 chars]; line: 1, column: 91] (through reference chain: info.movito.themoviedbapi.model.movies.MovieDb["belongs_to_collection"])

I didn't checked if there is any more missing fields.

c-eg commented 6 months ago

Hi, thanks for reporting this. I'll try to get a fix & new release out this evening.

c-eg commented 6 months ago

Seems the api documentation for "belongs_to_collection" is incorrect. It is listed as a string, but returns a json object.

c-eg commented 6 months ago

Version 2.0.3 has been released, please use this and the problem should be fixed :)