kotlin - 打包程序:无法找到类型io.realm.RealmList的读/写生成器

标签 kotlin realm parceler

我的应用程序需要打包一些具有 Realm 列表属性的对象。这是错误:

/StudioProjects/ML/dat-core-android/datcorelibrary/build/tmp/kapt3/stubs/release/com/ret/datcorelibrary/model/UserTest.java:29: error: Parceler: Unable to find read/write generator for type io.realm.RealmList for com.retoglobal.datingcorelibrary.model.UserTest#photos



在主要类别下面找到:

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)
    }


}

ProfilePhoto类
@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>()
}
}

最佳答案

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

关于kotlin - 打包程序:无法找到类型io.realm.RealmList的读/写生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47140044/

相关文章:

java - Java Parceler 问题

android - 更新到 WorkManager 1.0.0-alpha09 后编译错误

java - 通知 android 显示日期

spring - 带有 Spring Boot 2.1 WebMvcTest 的 Kotlin - 缺少 bean

ios - 删除一个 Realm 对象及其所有 RLMArrays

android - 将 Parceler 与安卓一起使用

java - 尝试在空对象上调用虚拟方法 'java.lang.String android.content.Context.getPackageName()'引用新 Activity

android - Realm 数据库与 Eclipse Android 项目集成

Android Realm 插入冲突忽略

parcelable - 将 Parceler 与带有构造函数的 Kotlin 数据类一起使用以进行序列化