Android 序列化(Serializable)出现错误 java.lang.RuntimeException: Parcelable encountered IOException writing

在传数据对象的时候,使用Serializable的时候,出现了一个错误,
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.**.Bean)

因为我的bean下面还是还嵌套了其他自定义的实体类,然而这个个实体类没有实现Serialzable接口,所以会出现这个类型转换的异常的错误.

解决办法:让所有的实体类都实现SerialZable接口就可以了。
如下:

public class AddPlanDialogBean implements Serializable {
    /**
     * order : {"margin_price":133.67,"client_num":"OP171026224746575054"}
     * bonus : [{"ub_id":"3","price":200,"total_price":5000,"use_end":"2017-12-19"}]
     */

    private OrderEntity order;
    private List bonus;

    public void setOrder(OrderEntity order) {
        this.order = order;
    }

    public void setBonus(List bonus) {
        this.bonus = bonus;
    }

    public OrderEntity getOrder() {
        return order;
    }

    public List getBonus() {
        return bonus;
    }


    public static class OrderEntity implements Serializable {
        /**
         * margin_price : 133.67
         * client_num : OP171026224746575054
         */

        private double margin_price;
        private String client_num;

        public void setMargin_price(double margin_price) {
            this.margin_price = margin_price;
        }

        public void setClient_num(String client_num) {
            this.client_num = client_num;
        }

        public double getMargin_price() {
            return margin_price;
        }

        public String getClient_num() {
            return client_num;
        }
    }

    public static class BonusEntity implements Serializable  {
        /**
         * ub_id : 3
         * price : 200
         * total_price : 5000
         * use_end : 2017-12-19
         */

        private String ub_id;
        private int price;
        private int total_price;
        private String use_end;

        public void setUb_id(String ub_id) {
            this.ub_id = ub_id;
        }

        public void setPrice(int price) {
            this.price = price;
        }

        public void setTotal_price(int total_price) {
            this.total_price = total_price;
        }

        public void setUse_end(String use_end) {
            this.use_end = use_end;
        }

        public String getUb_id() {
            return ub_id;
        }

        public int getPrice() {
            return price;
        }

        public int getTotal_price() {
            return total_price;
        }

        public String getUse_end() {
            return use_end;
        }

    }
}

本人菜鸟一个,有什么不对的地方希望大家指出评论,大神勿喷,希望大家一起学习进步!

你可能感兴趣的:(错误与异常,Android)