Reputation: 1974
My app needs to parcel some objects with realm list attributes. This is the error:
/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
Find below the main classes:
UserTest class
@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 class
@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()
UPDATE RealmListParcelConverter
abstract class RealmListParcelConverter<T:RealmObject> : CollectionParcelConverter<T, RealmList<T>>() {
override fun createCollection(): RealmList<T> {
return RealmList<T>()
}
}
Upvotes: 2
Views: 1179
Reputation: 1974
The approach suggested by @EpicPandaForce works. I added the RealmListParcelerConverter from the Github repository and let the annotation @Parcel(implementations = arrayOf(ProfilePhotoRealmProxy::class))
on the affected class.
Upvotes: 1