error: Parceler: Unable to find read/write generator for type io.realm.RealmList

827 views Asked by At

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

  1. 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()
  1. 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()
  1. 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.

1

There are 1 answers

0
undervoid On

finally I got one solution for this answer. All you need is add setter in my model Job. I'll give my whole code here:

  1. 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 = "",

            ) :RealmObject(){
@ParcelPropertyConverter(RealmStringListParcelConverter::class)
                        open var imageUrls: RealmList<RealmString>? = null set}
  1. 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()
  1. The class RealmStringListParcelConverter looks like this:
   class RealmStringListParcelConverter : RealmListParcelConverter<RealmString>() {
    override fun itemToParcel(input: RealmString?, parcel: Parcel?) {
        parcel?.writeParcelable(Parcels.wrap(RealmString::class.java, input), 0)
    }

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