So, I have this JSON Object
{
"name": "News",
"infos":[
{ "title":"hello",
"content":"this is the content",
"recent":true
},
{ "title":"Tax",
"content":"The European Commission is considering possible tax benefits",
"recent":true
},
{ "title":"Tax",
"content":"The European Commission is considering possible tax benefits",
}
]
I need to persist this object with Room(Android) using moshi to deserialize this object into my data classes which are
@JsonClass(generateAdapter = true)
@Entity(
tableName = "news"
)
data class News(
@ColumnInfo(name = "name")
val name:String = "News",
val infos:List<Info>,
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
val id: Int){
}
@JsonClass(generateAdapter = true)
@Entity(tableName = "info",
foreignKeys = [
ForeignKey(entity = News::class, parentColumns = ["id"], childColumns = ["info_id"])
],
indices = [Index("info_id")])
data class Info(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
var id: Int,
val title : String,
val content: String,
val recent: Boolean?,
@ColumnInfo(name = "info_id")
val infoId: Int) {
}
I have also created the Roomd Database and my @dao class @Insert fun. But I get this error :
error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.
private final java.util.List<com.example.data.Info> infos = null;