Didn't get any data from Retrofit

Aws :

i have a problem with Retrofit call. I'd wanted to get some data, just for testing purposes, to see if anything come, but as you can see, nothing comes. I've getting data like 0, 0.0, null.

Json response

    {
  "page": 1,
  "total_results": 1295,
  "total_pages": 65,
  "results": [
    {
      "vote_count": 1669,
      "id": 10515,
      "video": false,
      "vote_average": 8,
      "title": "Castle in the Sky",
      "popularity": 15.853,
      "poster_path": "\/npOnzAbLh6VOIu3naU5QaEcTepo.jpg",
      "original_language": "ja",
      "original_title": "天空の城ラピュタ",
      "genre_ids": [
        12,
        14,
        16,
        28,
        10751,
        10749
      ],
      "backdrop_path": "\/fnMzL4G6HYilH1w1leFXOY5b29m.jpg",
      "adult": false,
      "overview": "A young boy and a girl with a magic crystal must race against pirates and foreign agents in a search for a legendary floating castle.",
      "release_date": "1986-08-02"
    },
    {
      "vote_count": 154,
      "id": 487672,
      "video": false,
      "vote_average": 6.7,
      "title": "Reign of the Supermen",
      "popularity": 15.461,
      "poster_path": "\/e9TzqscNRUaG8HqEP3K1jUvi8pC.jpg",
      "original_language": "en",
      "original_title": "Reign of the Supermen",
      "genre_ids": [
        16,
        28,
        878
      ],
      "backdrop_path": "\/cdCMUHWyXBOsbLL4dOEPdCEtwM4.jpg",
      "adult": false,
      "overview": "In the wake of The Death of Superman, the world is still mourning the loss of the Man of Steel following his fatal battle with the monster Doomsday. However, no sooner as his body been laid to rest than do four new bearers of the Superman shield come forward to take on the mantle. The Last Son of Krypton, Superboy, Steel, and the Cyborg Superman all attempt to fill the vacuum left by the world's greatest champion. Meanwhile, Superman's death has also signaled to the universe that Earth is vulnerable. Can these new Supermen and the rest of the heroes prove them wrong?",
      "release_date": "2019-01-13"
    }
  ]
}

Interface call

@GET("3/discover/movie?api_key=APIKEY&with_genres=27")
Call<model> getABC();

Retrofit call

    String url = "https://api.themoviedb.org/";

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(url)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    apiCall api = retrofit.create(apiCall.class);

    Call<model> call = api.getABC();
    call.enqueue(new Callback<model>() {
        @Override
        public void onResponse(Call<model> call, Response<model> response) {
            if (!response.isSuccessful()){
            }
            List<model> list = Collections.singletonList(response.body());

            for (model model : list) {
                String content = "";
                content += model.getVote_count() + "\n";
                content += model.getVote_average() + "\n";
                content += model.getOverview() + "\n\n\n";

                System.out.println(content);
            }
        }

        @Override
        public void onFailure(Call<model> call, Throwable t) {

        }
    });
}

POJO

public class model {
@SerializedName("vote_count")
private int vote_count;
@SerializedName("vote_average")
private double vote_average;
@SerializedName("overview")
private String overview;

public int getVote_count() {
    return vote_count;
}

public double getVote_average() {
    return vote_average;
}

public String getOverview() {
    return overview;
}

What should I change in the code? I will appreciate every hint. The code that I've received from the call is 200 - so call is succesfull, is there something with my pojo class?

*Edited POJO

public class model {

@SerializedName("results")
@Expose
private List<movies> results;

public List<movies> getResults() {
    return results;
}

class movies {
    @SerializedName("vote_count")
    @Expose
    private Integer voteCount;
    @SerializedName("vote_average")
    @Expose
    private Double voteAverage;
    @SerializedName("overview")
    @Expose
    private String overview;
 }
}

edited retrofit call

public void onResponse(Call<model> call, Response<model> response) {
            if (!response.isSuccessful()){
            }
            List<model> list = Collections.singletonList(response.body());

            for (model model : list) {
                System.out.println(model.getResults());
            }
        }

Here's the part, what I've received.

com.example.x.model$movies@5f6763b, 
com.example.x.model$movies@e988158,
com.example.x.model$movies@6812b1,

Why doesn't it get properly names?

rawcoder064 :

Your Model class should look like the following:

public class Model {
@SerializedName("page")
private int page;

@SerializedName("results")
private List<Result> results;

@SerializedName("total_results")
private int total;

@SerializedName("total_pages")
private int totalPages;

//.......getter setter methods

}


public class Result{
@SerializedName("vote_count")
private int voteCount;

@SerializedName("vote_average")
private double voteAverage;

@SerializedName("overview")
private String overView;

//.....other fields
//......getter setter methods
}

Then the retrofit call should be like this:

Call<model> call = api.getABC();
call.enqueue(new Callback<Model>() {
        @Override
        public void onResponse(Call<Model> call, Response<Model> response) {
            if (response.isSuccessful()) {
                List<Result> results=response.body().getResults();
                for(Result result:results){
                Log.d(TAG,"Result: "+result.getVoteCount())                    
               }



            }
        }

        @Override
        public void onFailure(Call<Model> call, Throwable t) {

        }
    });

Happy coding.... :)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=163142&siteId=1