Compile Time Error When Converting RealmObject Class To Kotlin

663 views Asked by At

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?

1

There are 1 answers

0
Ricardo On

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)