Alexander
Alexander

Reputation: 45

Unable to store nested json in Android Room Database Kotlin

I have an api returning a json response im having trouble trying to store the netsted json parts keep getting error "Entities and POJOs must have a usable public constructor"

heres the json response

{
"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"
}]}

heres is my data classes

@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
)

Upvotes: 0

Views: 256

Answers (1)

Vikas
Vikas

Reputation: 468

You have to create custom converter and for your nested jaon. Nodes. Because Room only verify parent node without Converter. Look this example Link

Upvotes: 1

Related Questions