I am getting the following exception on my Retrofit2 call:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 22311 path $[1].programme[3].credits.presenter
I probably know why it is being thrown. Some "credits" objects have more than one "presenters", and they are given as JSON Arrays ({"presenter":["Barbara Schledduytkew","Hubert Muckhutgoldwes"]}), however, some others have only a single "presenter", and it is given as a JSON Object ({"presenter":"Rosalynda Demstogtrojkt"})
I need to find a way to get the presenter items parsed in both cases. I guess that I have to write my own custom TypeAdapter, but I am not sure and need help. Thanks in advance.
Retrofit Instance:
retrofit = new Retrofit.Builder()
                .baseUrl(Constants.URL_HOST)
                .client(okHttpClient.build())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
Credits Class:
public class Credits {
    @SerializedName("director")
    @Expose
    private List<String> director;
    @SerializedName("actor")
    @Expose
    private List<String> actor = null;
    @SerializedName("presenter")
    @Expose
    private List<String> presenter;
    @SerializedName("commentator")
    @Expose
    private String commentator;
    public List<String> getDirector() {
        return director;
    }
    public void setDirector(List<String> director) {
        this.director = director;
    }
    public List<String> getActor() {
        return actor;
    }
    public void setActor(List<String> actor) {
        this.actor = actor;
    }
    public List<String> getPresenter() {
        return presenter;
    }
    public void setPresenter(List<String> presenter) {
        this.presenter = presenter;
    }
    public String getCommentator() {
        return commentator;
    }
    public void setCommentator(String commentator) {
        this.commentator = commentator;
    }
}
 
     
    