1

This is my original RealmObject with Parceler annotation.

@Parcel(implementations = {AlbumRealmProxy.class},
        value = Parcel.Serialization.BEAN,
        analyze = {Album.class})
public class Album extends RealmObject {

    @PrimaryKey
    @SerializedName("id")
    private String id;
    @SerializedName("artist_id")
    private String artistId;
    @SerializedName("title")
    private String title;
    @SerializedName("artist_name")
    private String artist;
    @SerializedName("images")
    private RealmList<Artwork> artwork;
    @SerializedName("tracks")
    private RealmList<Track> tracks;
    @SerializedName("artist_bio")
    private String artistBio;

    @ParcelPropertyConverter(RealmListParcelConverter.class)
    public void setArtwork(RealmList<Artwork> artwork) {
        this.artwork = artwork;
    }

    @ParcelPropertyConverter(RealmListParcelConverter.class)
    public void setTracks(RealmList<Track> tracks){
        this.tracks = tracks;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setArtist(String artist) {
        this.artist = artist;
    }

    public RealmList<Artwork> getArtwork() {
        return artwork;
    }

    public String getArtist() {
        return artist;
    }

    public String getArtistId() {
        return artistId;
    }

    public String getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public RealmList<Track> getTracks() {
        return tracks;
    }

    public String getArtistBio() {
        return artistBio;
    }
}

On converting to Kotlin I get the following generated class;

@Parcel(implementations = arrayOf(AlbumRealmProxy::class), value = Parcel.Serialization.BEAN, analyze = arrayOf(Album::class))
open class Album : RealmObject() {

    @PrimaryKey
    @SerializedName("id")
    var id: String? = null
    @SerializedName("artist_id")
    val artistId: String? = null
    @SerializedName("title")
    var title: String? = null
    @SerializedName("artist_name")
    var artist: String? = null
    @SerializedName("images")
    @set:ParcelPropertyConverter(RealmListParcelConverter::class)
    open var artwork: RealmList<Artwork>? = null
    @SerializedName("tracks")
    @set:ParcelPropertyConverter(RealmListParcelConverter::class)
    open var tracks: RealmList<Track>? = null
    @SerializedName("artist_bio")
    val artistBio: String? = null
}

The compile time error is as follows:

Error:(5, 17) Unresolved reference: AlbumRealmProxy
Error:(16, 27) Only 'const val' can be used in constant expressions
Error:(16, 35) Unresolved reference: AlbumRealmProxy
Error:(16, 35) An annotation parameter must be a compile-time constant

[KOTLIN] deleting /Users/dev/RAG Apps/Songa/app/build/tmp/kotlin-classes/debug on error
[KOTLIN] deleting /Users/dev/RAG Apps/Songa/app/build/tmp/kotlin-classes/debug on error

I am using the Kotlin kapt annotation processor for Parceler but the project still wont compile.

Is there some extra configuration required?

Alex Kombo
  • 3,256
  • 8
  • 34
  • 67
  • Do you really need Parcelable for **managed** RealmProxy classes? – EpicPandaForce May 25 '17 at 10:56
  • @EpicPandaForce Yes. I don't always save the objects to Realm hence re-querying won't work in some cases. – Alex Kombo May 25 '17 at 11:50
  • But if you don't save the object, then it's not a **managed** RealmProxy, it's an **unmanaged** RealmObject. Hence the question. Because the `implementations={__RealmProxy::class.java}` is for parcelling managed proxies. – EpicPandaForce May 25 '17 at 12:01
  • Maybe the answer in https://stackoverflow.com/questions/38910246/kotlin-realm-and-parcel can be useful for you – geisshirt May 25 '17 at 17:53

1 Answers1

0

In my case, I have this package: com.path.model.Album, and I have to use:

import io.realm.com_path_model_AlbumRealmProxy

...
@Parcel(implementations = arrayOf(com_path_model_AlbumRealmProxy::class)
Ricardo
  • 2,086
  • 25
  • 35