I was trying to make a dataclass for Room and the class also have a field which is for the views only. I do not want to save the data into Room.
@Entity(tableName = "MyTable")
@Parcelize
data class MyTable(
@SerializedName("id") @PrimaryKey val id: String,
@SerializedName("field1") val field1: String?,
var selected: Boolean? = false //todo use @Ignore
) : Parcelable
The above code works. However whenever I tried to use @Ignore
annotation with the variable with selected
variable. Its giving me the following error
error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
If I remove the variable from the constructor like
@Entity(tableName = "MyTable")
@Parcelize
data class MyTable(
@SerializedName("id") @PrimaryKey val id: String,
@SerializedName("field1") val field1: String?
) : Parcelable{
var selected: Boolean? = false //todo use @Ignore
}
The field selected
will not be written into the parcel. How can I keep the variable into the class without making a column and still keeping it into the parcel?
Thanks