Hi! What im doing wrong to deserialize list of obj...
# ktor
q
Hi! What im doing wrong to deserialize list of objects?
Copy code
install(ContentNegotiation) {
        json()
    }

    val client = HttpClient(CIO)

    routing {
        get("/users") {
            val users: List<User> = client.get("$host/api/v4/users?private_token=$token").body()
            call.respond(users)
        }
    }
Copy code
@Serializable
data class User(
    val id: String,
    val username: String,
)
this code returns this error
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class kotlin.collections.List
g
What is your dependency? I just had the same problem. You need to use
io.ktor:ktor-serialization-kotlinx-json-jvm
and not
org.jetbrains.kotlinx:kotlinx-serialization-json
q
im using a first one, but guess i found a problem - its coze ContentNegotiation for client and for server named same? and u cant to install both, without alias for import
Copy code
...
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation as ContentNegotiationServer
...


install(ContentNegotiationServer) {
    json()
}

val client = HttpClient(CIO) {
    install(ContentNegotiation) {
        json()
    }
}

routing {
    get("/users") {
        val users: List<User> = client.get("$host/api/v4/users?private_token=$token").body()
        call.respond(users)
    }
}
and its work
guess in my route, deserialization maked by client, not by server
g
Could be. There are seperate dependency files for client and server for ContentNegotiation with seperate packages. (one
io.-ktor.server
the other
io.ktor.client
). Maybe you should put the initialization in two different files. Or you live with the alias or a full package name in the
install()
-call
q
Sure, I will separate it latter
thank u!!