Android序列化出现java.lang.RuntimeException: Parcelable encountered IOException writing serializable o...

bug

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.loan.market.bean.ShopBean$DataBean)

出现的场景
                val intent = Intent(context, DetailActivity::class.java)
                val bundle = Bundle()
                bundle.putSerializable("databeans", databeans[position])//序列化
                intent.putExtras(bundle)
                context.startActivity(intent)
分析

因为我的ShopBean里面嵌套一个DataBean,DataBean嵌套了LoanProductRequiresBean ,DataBean序列化了,而ShopBean和LoanProductRequiresBean 没有序列化,导致 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.loan.market.bean.ShopBean$DataBean),纠错:将LoanProductRequiresBean 序列化:

class ShopBean{

    var code: Int = 0
    var isSuccess: Boolean = false
    var message: String? = null
    var page: Any? = null
    var data: ArrayList? = null

    class DataBean : Serializable{

        var id: Int = 0
        var createTime: Long = 0
        var modifyTime: Long = 0
        var status: Int = 0
        var sortWeight: Int = 0
        var productName: String? = null
        var bannerUrl: String? = null
        var loanMoney: Long? = null
        var applyDay: String? = null
        var interest: String? = null
        var loanTerm: String? = null
        var loanRemarks: String? = null
        var forwardUrl: String? = null
        var loanFlow1: String? = null
        var loanFlow2: String? = null
        var loanFlow3: String? = null
        var loanFlow4: String? = null
        var newDate: Long = 0
        var googleDate: Long = 0
        var loanProductRequires: List? = null

        class LoanProductRequiresBean  : Serializable{

            var id: Int = 0
            var createTime: Long = 0
            var modifyTime: Any? = null
            var productId: Int = 0
            var description: String? = null
        }
    }

}
总结:

如果一个类序列化,则将这个类所有嵌套的实体类都实现序列化。

你可能感兴趣的:(Android序列化出现java.lang.RuntimeException: Parcelable encountered IOException writing serializable o...)