无法在Android Room Database Kotlin中存储嵌套json



我有一个api返回json响应,我在尝试存储netsted json部分时有麻烦,不断得到错误"实体和pojo必须有一个可用的公共构造器">

这里是json响应

{
"id": 1,
"category": {
"id": 1,
"title": "Billing"
},
"type": "Site",
"title": "No Service available",
"status": 0,
"priority": 10,
"created_at": "Sat 30, Oct 2021 19:22",
"contents": [{
"id": 8,
"content": "Dear Customer/Partner,nOur engineers have been able to restore services for the moment. They are continuing to work on a permanent resolution.nThis outage was caused by a technical error during a routine maintenance activity on our database which cascaded to a larger outage.",
"isOwn": true,
"username": "Adiuta Demo",
"created_at": "30.10.21 19:22:02"
}]}

这是我的数据类

@Entity(tableName = "tickets")
data class Ticket(
@PrimaryKey val id: Int,
val title: String,
val type: String,
val category: Category,
val contents: List<Content>,
val status: Int,
val priority: Int,
val created_at: String
)
data class Content(
val id: Int,
val username: String,
val content: String,
val created_at: String,
val isOwn: Boolean,
)

data class Category(
val id: Int,
val title: String
)

您必须为嵌套的jaon创建自定义转换器。节点。因为Room只验证父节点而不验证Converter。看看这个例子链接

最新更新