Im encountering a strange problem: the default beh...
# ktor
z
Im encountering a strange problem: the default behavior of the .body() method doesn't use the proper serializers, but if I do it manually then it works This works:
Copy code
private suspend inline fun <reified T> post(endpoint: String, crossinline body: () -> Any): T {
        return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            val text = <http://httpClient.post|httpClient.post>("$API_URL/$endpoint") {
                parameter("key", API_KEY)
                setBody(body())
            }.bodyAsText()

            json.decodeFromString(serializer<T>(), text)
        }
    }
This doesn't work:
Copy code
private suspend inline fun <reified T> post(endpoint: String, crossinline body: () -> Any): T {
        return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            <http://httpClient.post|httpClient.post>("$API_URL/$endpoint") {
                parameter("key", API_KEY)
                setBody(body())
            }.body()
        }
    }
r
Did you install the Content Negotiation plugin for your Ktor client?
z
yep
it only happens for typealias with a serializer normal classes work fine
z
type erasure problem?
z
could be, I'm not sure how I'd check