-1

I'M using retfofit2 and i have problem with creating model class I cant creat model of this .json file...

I get in throwable wrong com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 12 path $.movies

I think this problem of child "movies": genres

My json

MainActivity

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://server/api/all/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    MainInterface mainApi = retrofit.create(MainInterface.class);

    Call<MainModel> mainCall = mainApi.getMoviess();

    mainCall.enqueue(new Callback<MainModel>() {
        @Override
        public void onResponse(Call<MainModel> call, Response<MainModel> response) {
            Log.d("Retrofittt", "onResponse: ok");

        }

        @Override
        public void onFailure(Call<MainModel> call, Throwable t) {
            Log.d("Retrofittt", "onFailure: "+t);
        }
    });

MainModel

public class MainModel {


private String genre;
private MoviesBean movies;

//getter and setters

public class MoviesBean {


    private String content_year;
    private String content_id;
    private String base_url;
    private String base_url_link;
    private String content_rating_age;
    private String movie_link;
    private String content_title;
    private String content_text_small;
    private String rating_kinopoisk;
    private String rating_imdb;
    private String rating_kinodelux;
    private String link_to_movie;
    private String content_poster_small;
    private String content_poster;
    private GenresBean genres;
      
    ///getters and setters  
  

}
public class GenresBean {

    private String genre_name;
    private String genre_id;
    private String base_url_link;

   ///getters and setters 
}

}

MainInterface

    interface MainInterface {

    @GET("1")
    Call<MainModel> getMoviess();
}
Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50

2 Answers2

1

your interface would be like below

interface MainInterface {

    @GET("1")
    Call<ArrayList<MainModel>> getMoviess();
}

Because in your JSON it returns a list or your MainModel like MovieModel. And in your case, you just get only MainModel from the response.

Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50
0

please try below code, hopes it'll help

public class MainModel {
    
    
    private String genre;
    private ArrayList<MoviesBean> movies;
    
    //getter and setters
    
    public class MoviesBean {
    
    
        private String content_year;
        private String content_id;
        private String base_url;
        private String base_url_link;
        private String content_rating_age;
        private String movie_link;
        private String content_title;
        private String content_text_small;
        private String rating_kinopoisk;
        private String rating_imdb;
        private String rating_kinodelux;
        private String link_to_movie;
        private String content_poster_small;
        private String content_poster;
        private ArrayList<GenresBean> genres;
          
        ///getters and setters  
      
    
    }
    public class GenresBean {
    
        private String genre_name;
        private String genre_id;
        private String base_url_link;
    
       ///getters and setters 
    }
nnwh
  • 71
  • 2