I'm programing a project by using Kotlin:
- Kotlin version: 1.1.3-2
- Parcerler version 1.1.9
- Realm version 3.2.0
I am using Parceler for FragmentArgs with RealmObjects and getting the following crash.
Parceler: Unable to find read/write generator for type io.realm.RealmList
- My Class Job like this:
@Parcel(value = Parcel.Serialization.BEAN, analyze = arrayOf(Job::class))
open class Job(
@PrimaryKey open var tweetId: Long? = -1L,
open var text: String = "",
open var title: String = "",
open var longitude: Double? = null,
open var latitude: Double? = null,
open var link: String = "",
@ParcelPropertyConverter(RealmStringListParcelConverter::class)
open var imageUrls: RealmList<RealmString>? = null
) : RealmObject()
- The class RealmString looks like this: My class RealmString.kt like this:
@Parcel(value = Parcel.Serialization.BEAN, analyze = arrayOf(RealmString::class))
open class RealmString(
open var value: String = ""
) : RealmObject()
- The class RealmListParcelConverter looks like this:
public class RealmListParcelConverter implements TypeRangeParcelConverter<RealmList<? extends RealmObject>, RealmList<? extends RealmObject>>
{
private static final int NULL = -1;
@Override
public void toParcel(RealmList<? extends RealmObject> input, Parcel parcel)
{
parcel.writeInt(input == null ? NULL : input.size());
if(input != null)
{
for(RealmObject item : input)
{
parcel.writeParcelable(Parcels.wrap(item), 0);
}
}
}
@Override
public RealmList fromParcel(Parcel parcel)
{
int size = parcel.readInt();
RealmList list = new RealmList();
for(int i = 0; i < size; i++)
{
Parcelable parcelable = parcel.readParcelable(getClass().getClassLoader());
list.add((RealmObject) Parcels.unwrap(parcelable));
}
return list;
}
}
UPDATE
I have tried add implementations = RealmStringRealmProxy and implementations = JobRealmProxy , still get the same issue.
UPDATE 2
Update Realm version to 3.5.0 , still get the same issue.
finally I got one solution for this answer. All you need is add
setter
in my modelJob
. I'll give my whole code here: