Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Parceler 1.0.3 with Realm
// Specific class for a RealmList<Bar> field
public class BarListParcelConverter extends RealmListParcelConverter<Bar> {
@Override
public void itemToParcel(Bar input, Parcel parcel) {
parcel.writeParcelable(Parcels.wrap(input), 0);
}
@Override
public Bar itemFromParcel(Parcel parcel) {
return Parcels.unwrap(parcel.readParcelable(Bar.class.getClassLoader()));
}
}
// Abstract class for working with RealmLists
public abstract class RealmListParcelConverter<T extends RealmObject> extends CollectionParcelConverter<T, RealmList<T>> {
@Override
public RealmList<T> createCollection() {
return new RealmList<T>();
}
}
@Parcel(implementations = { BarRealmProxy.class }, value = Parcel.Serialization.BEAN, analyze = { Bar.class })
public class Bar extends RealmObject {
private String baz;
public void setBaz(String baz) {
this.baz = baz;
}
public String getBaz() {
return baz;
}
}
@Parcel(implementations = { FooRealmProxy.class }, value = Parcel.Serialization.BEAN, analyze = { Foo.class })
public class Foo extends RealmObject {
private RealmList<Bar> bars;
@ParcelPropertyConverter(BarListParcelConverter.class)
public void setBars(RealmList<Bar> bars) {
this.bars = bars;
}
public RealmList<Bar> getBars() {
return bars;
}
}
@Shajeel-Afzal

This comment has been minimized.

Show comment
Hide comment
@Shajeel-Afzal

Shajeel-Afzal Dec 22, 2015

Hi, Thank you for the gist. Can you please tell me why RealmProxy class is not being created in my case?

Hi, Thank you for the gist. Can you please tell me why RealmProxy class is not being created in my case?

@Shajeel-Afzal

This comment has been minimized.

Show comment
Hide comment
@Shajeel-Afzal

Shajeel-Afzal Dec 22, 2015

Also the imports for BarListParcelConverter.java are:

import android.os.Parcel;
import org.parceler.Parcels;

Right?

Also the imports for BarListParcelConverter.java are:

import android.os.Parcel;
import org.parceler.Parcels;

Right?

@patloew

This comment has been minimized.

Show comment
Hide comment
@patloew

patloew Apr 6, 2016

I wrote a generic adapter which works for all RealmLists: RealmListParcelConverter.java

patloew commented Apr 6, 2016

I wrote a generic adapter which works for all RealmLists: RealmListParcelConverter.java

@QifanViseo

This comment has been minimized.

Show comment
Hide comment
@QifanViseo

QifanViseo Jul 19, 2017

@patloew Hello i have tried your things which show an error : read/write generator for type io.realm.RealmList do you have any ideas of this? Thx

@patloew Hello i have tried your things which show an error : read/write generator for type io.realm.RealmList do you have any ideas of this? Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment