https://kotlinlang.org logo
Title
z

zero_coding

08/28/2020, 12:45 PM
e

Eric Grimsborn

08/28/2020, 12:52 PM
That object is not serializable. What content negotiation are you using?
I tried using ktor+exposed for a side project with kotlinx.serialization and had:
@Serializable
data class ChecklistResponse(
    val id: UUID, // requires custom serializer
    val name: String
)

class Checklist(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object: UUIDEntityClass<Checklist>(Checklists)
    var name by Checklists.name
    val items by ChecklistItem referrersOn ChecklistItems.checklist
}

suspend fun getChecklists(): List<ChecklistRes> {
    return db.transaction { Checklist.all().map {
        ChecklistResponse(it.id.value, it.name) }
    }
}
i can then
call.respond(getChecklists())
There are probably nicer solutions but it works well enough and by having the response class separately I can provide a consistent API when I need to make changes to my DAO.
z

zero_coding

08/28/2020, 4:37 PM
@Eric Grimsborn Sorry for the late response. As content negotiation I use
install(ContentNegotiation) {
        gson {
        }
    }
Aha....I have to manually serialize it
Thanks a lot for your help
j

jorge.rego

08/28/2020, 7:11 PM
Ey @zero_coding, I’ve published a basic example of how to do all of these basic tasks. Have a look here: https://github.com/mathias21/KtorEasy
👍 1