Using parceler (@Parcel) with Realm.io (Android)

I have the following code that causes the error: Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm

It worked fine without extends RealmObject , however I want to use Realm to easily add to the database. Is there a way to push out RealmObject fields and just use the main pojo fields for @Parcel?

 @Parcel public class Feed extends RealmObject{ int id; public String text; public String time_created; String time_modified; int comments_count; int likes_count; String feed_type; int obj_id; String image; String user_name; String user_earthmile_points; boolean liked; boolean commented; boolean is_private; String url; int feed_creator_id; } 
+4
source share
2 answers

EDIT # 2 : Actually, I found a way to make it work :). See Updated Answer below.

EDIT No. 1 . While the application compiles just fine, it crashes when trying to create Parcel with an error: org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy . The Realm team has officially recognized that it is currently not possible to implement Parcelable on RealmObject s. It is unclear whether / when this will be allowed.


With Parceler v0.2.16 you can do this:

 @RealmClass // required if using JDK 1.6 (unrelated to Parceler issue) @Parcel(value = Parcel.Serialization.BEAN, analyze = { Feed.class }) public class Feed extends RealmObject { // ... } 

Then use Parcels.wrap(Feed.class, feed) instead of Parcels.wrap(feed) everywhere, otherwise your application will fail using org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy .

+14
source

All classes that extend RealmObject will have the corresponding RealmProxy class created by the annotation processor. Parceler should be aware of this class. Note that the class is not available until the project has been compiled at least once.

 @Parcel(implementations = { PersonRealmProxy.class }, value = Parcel.Serialization.BEAN, analyze = { Person.class }) public class Person extends RealmObject { // ...} 
+1
source

Source: https://habr.com/ru/post/978946/


All Articles