I’m having issues with deserializing JSON to a dat...
# ktor
r
I’m having issues with deserializing JSON to a data class with ktor client. I have the following code:
Copy code
import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.features.json.JacksonSerializer
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.request.header
import io.ktor.client.request.parameter
import io.ktor.client.request.request
import io.ktor.client.request.url

class FooApiClient(val fooApiUrl: String, val objectMapper: ObjectMapper, val userAgent: String) {
    val client = HttpClient(CIO) {
        install(JsonFeature) {
            serializer = JacksonSerializer { objectMapper }
        }
    }

    suspend fun search(
            q: String
    ): FooApiResponse {
        return client.request {
            header("User-Agent", userAgent)
            parameter("q", q)
            url(fooApiUrl)
        }
    }
}
Which gives exception:
Copy code
No transformation found: class <http://kotlinx.coroutines.io|kotlinx.coroutines.io>.ByteBufferChannel -> class FooApiResponse
io.ktor.client.call.NoTransformationFoundException: No transformation found: class <http://kotlinx.coroutines.io|kotlinx.coroutines.io>.ByteBufferChannel -> class FooApiResponse
	at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:88)