Retrofit 泛型解析遇到com.google.gson.internal.LinkedTreeMap cannot be cast to objec

在使用Retrofit进行网络请求时出现了以下异常:

java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.fr.konwledge.bean.TestBean

泛型解析错误。最初我的JavaBean类的写法如下:

public class TodayListBean {
    
    private boolean isError;
    private ResultsBean results;
    private List category;

    public boolean isError() {
        return isError;
    }

    public ResultsBean getResults() {
        return results;
    }

    public List getCategory() {
        return category;
    }

    public static class ResultsBean {
        private List Android;
        private List App;
        private List iOS;

        public List getAndroid() {
            return Android;
        }

        public void setAndroid(List android) {
            Android = android;
        }

        public List getApp() {
            return App;
        }

        public void setApp(List app) {
            App = app;
        }

        public List getiOS() {
            return iOS;
        }

        public void setiOS(List iOS) {
            this.iOS = iOS;
        }


    }
}

后改成如下,解决了问题。

public class TodayListBean {
    
    private boolean isError;
    private ResultsBean results;
    private List category;

    public boolean isError() {
        return isError;
    }

    public ResultsBean getResults() {
        return results;
    }

    public List getCategory() {
        return category;
    }

    public static class ResultsBean {
        private List Android;
        private List App;
        private List iOS;

        public List getAndroid() {
            return Android;
        }

        public void setAndroid(List android) {
            Android = android;
        }

        public List getApp() {
            return App;
        }

        public void setApp(List app) {
            App = app;
        }

        public List getiOS() {
            return iOS;
        }

        public void setiOS(List iOS) {
            this.iOS = iOS;
        }

    }
}

你可能感兴趣的:(Retrofit 泛型解析遇到com.google.gson.internal.LinkedTreeMap cannot be cast to objec)