0

Not sure how to add additional field which is not part of json Response. Found similar issue & i tried the solution but no luck for me :( , getting an error, not sure how to fix it.

here is code snippet for data class :

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

@Parcelize
@Entity(tableName = "personality")
data class Personality(

    @SerializedName("id")
    @PrimaryKey(autoGenerate = false)
    val id: Int ,

    @SerializedName("full_name")
    val fullName: String,

    @SerializedName("born")
    val born: String?,

    // 'isFavourite' is additional field other than JSON Response
   private var _isFavourite: Boolean = false
): Parcelable {
   var isFavourite
   get() = _isFavourite?:false
    set(value) {
        _isFavourite = value
    }
} 


khan umer
  • 113
  • 5
  • What's the error? And did you try just adding the `@SerializedName("unused")` annotation above `_isFavourite`? As a sidenote, usually your API response & table should not be the same. Having a converter would be minimal code, decouple your DB and API, and help distinguish a DB related action from an API related action. – Jake Lee Jan 02 '22 at 19:36

0 Answers0