Skip to content

Instantly share code, notes, and snippets.

@Rexee
Last active August 3, 2018 01:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rexee/3ec92b759b3a944d4ad4b28666b2479c to your computer and use it in GitHub Desktop.
Save Rexee/3ec92b759b3a944d4ad4b28666b2479c to your computer and use it in GitHub Desktop.
Parceler and RealmList
@Parcel(implementations = { CountryRealmProxy.class },
value = Parcel.Serialization.FIELD,
analyze = { Country.class })
public class Country extends RealmObject {
@ParcelPropertyConverter(RealmListParcelConverter.class)
public RealmList<RealmString> languages;
}
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment