【问题标题】:Parceler: Unable to find read/write generator for type io.realm.RealmListParceler:找不到 io.realm.RealmList 类型的读/写生成器
【发布时间】:2017-11-06 15:11:06
【问题描述】:

我的应用需要使用领域列表属性来打包一些对象。这是错误:

/StudioProjects/ML/dat-core-android/datcorelibrary/build/tmp/kapt3/stubs/release/com/ret/datcorelibrary/model/UserTest.java:29:错误:Parceler:找不到读/写com.retoglobal.datingcorelibrary.model.UserTest#photos 的 io.realm.RealmList 类型的生成器

在下面找到主要类:

UserTest 类

@Parcel(implementations = arrayOf(UserTestRealmProxy::class),
        value = Parcel.Serialization.BEAN)

@RealmClass
open class UserTest(

    @PrimaryKey open var id: String = "",
    open var years : Int = 0,
    @SerializedName("profile_photo") open var profilePhoto: ProfilePhoto? = ProfilePhoto("www", "fd"),
    open var location : Property? = null,
    open var town : String? = "",
    open var username : String? = "") : RealmObject()
{

    @ParcelPropertyConverter(RealmUserTestParcelConverter::class)
    open var photos : RealmList<ProfilePhoto>? = null
    set

}

class RealmUserTestParcelConverter : RealmListParcelConverter<ProfilePhoto>() {

    override fun itemFromParcel(parcel: android.os.Parcel?): ProfilePhoto {
        return Parcels.unwrap(parcel?.readParcelable<Parcelable>(ProfilePhoto::class.java.classLoader))

    }

    override fun itemToParcel(item: ProfilePhoto?, parcel: android.os.Parcel?) {
        parcel?.writeParcelable(Parcels.wrap(ProfilePhoto::class.java, item), 0)
    }


}

个人资料照片类

@Parcel(implementations = arrayOf(ProfilePhotoRealmProxy::class),
        value = org.parceler.Parcel.Serialization.BEAN)
@RealmClass
open class ProfilePhoto(
        @SerializedName("m") open var photo : String = "",
        open var id : String = "") : RealmObject()

更新 RealmListParcelConverter

abstract class RealmListParcelConverter<T:RealmObject> : CollectionParcelConverter<T, RealmList<T>>() {

override fun createCollection(): RealmList<T> {
    return RealmList<T>()
}
}

【问题讨论】:

标签: kotlin realm parceler


【解决方案1】:

@EpicPandaForce 建议的方法有效。我从 Github 存储库中添加了 RealmListParcelerConverter,并将 annotation @Parcel(implementations = arrayOf(ProfilePhotoRealmProxy::class)) 放在受影响的类上。

【讨论】:

  • 您的转换器看起来如何?我也在尝试相同的方法,但总是失败并出现异常:代码生成未成功完成
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多