2014-12-23 2 views
4

나는이 오류 발생 다음 코드 : 그러나 나는 데이터베이스에 넣어 영역을 사용하려면, Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm사용 Realm.io (안드로이드)와 (@Parcel)

그것은 extends RealmObject없이 모두 잘 작동되었다 용이하게. RealmObject 필드를 exlcude하고 @Parcel에 대한 기본 pojo 필드를 사용하는 방법이 있습니까?

@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; 

    } 
+1

는 –

+0

기술적으로는, 나는 그것이 RealmObject을 소포 의미가있는 사용 사례를 본 적이 없다 https://github.com/johncarl81/parceler/issues/57 참조하십시오. 기본 키만 보내야합니다. – EpicPandaForce

답변

13

편집 # 2 : 사실, 나는 :) 그것이 작동되도록하는 방법을 발견했다. 아래의 업데이트 된 답변을 참조하십시오.

편집 # 1 : org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy : 응용 프로그램이 잘 컴파일되지만 실제로 오류와 Parcel을 만들려고 할 때, 그것은 충돌합니다. 렐름 팀은 officially acknowledgedParcelableRealmObject에 구현할 수 없다고합니다. 이것이 언제/언제 해결되는지는 확실하지 않습니다.


Parceler v0.2.16, 당신은이 작업을 수행 할 수 있습니다

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

그런 다음, 그렇지 않으면 앱이 org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy와 충돌합니다, 대신 사방 Parcels.wrap(feed)Parcels.wrap(Feed.class, feed)를 사용합니다.

+0

고맙습니다. – jgnt32

+0

직렬화를 사용합니까? 직렬화가 소포보다 10 배 더 느린다고 들었습니다. 나는 성능에 타협하고 싶지 않다. 그래서이 기술을 사용하거나 다른 작업을해야합니까? – penduDev

+1

@penduDev 아니요. Parceler는 여전히 표준 Android'Parcel'을 만듭니다. 걱정할 필요가 없습니다. 그게 전부입니다 :) (실제로는 'Parcel'을 만드는 것조차도 "직렬화"의 한 형태입니다. 따라서 "직렬화가 소포보다 10 배 느립니다"라는 말은 올바르지 않습니다. Java Serializable 인터페이스는'Parcel'을 만드는 것보다 느리고 * *가있는 이유는''Serializable'은 많은 GC를 유발하는 많은 임시 객체를 생성합니다 (http : //www.developerphil. com/parcelable-vs-serializable /)). –

1

RealmObject를 확장하는 모든 클래스에는 주석 프로세서에서 만든 일치하는 RealmProxy 클래스가 있습니다. 파셀러는이 클래스를 알고 있어야합니다. 프로젝트가 적어도 한 번 컴파일되기 전까지는 클래스를 사용할 수 없습니다.

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