Build Failure while using @Parcelize with Android AC Room's @Entity


#1

What is the correct way to parcelize(maybe using @Parcelize) a data class annotated with @Entity from Android’s Room.

Straight forward implementation results in build failure with following message as shown in the screen shot:

Sample Code i used:

@SuppressLint("ParcelCreator")
@Parcelize
@Entity(tableName = "foo")
data class Foo(@PrimaryKey @ColumnInfo(name = "foobar1") val foobar1: Int,
                       @ColumnInfo(name = "foobar2") val foobar2: Int) : Parcelable {
// Parcelable's impl
}

#2

This way works for me.

import android.arch.persistence.room.Entity
import android.arch.persistence.room.Ignore
import android.arch.persistence.room.PrimaryKey
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
@Entity(tableName = "movie")
class Movie(
        @PrimaryKey(autoGenerate = false)
        val id: Int = 0,
        val overview: String = "",
        val popularity: Double = 0.0,
        val title: String = "",
) : Parcelable {
    @Ignore
    constructor() : this(0) {
    }
}