https://kotlinlang.org logo
#ktor
Title
# ktor
g

Gokhan Alıcı

09/23/2023, 8:38 PM
Has anyone experienced a problem while parsing json api response when content type is not “application/json” ?
I’m trying to send a request and parse server’s response using ktor which is quite straightforward. But unfortunately, server uses wrong “content-type”, “text/html” instead of “application/json” which causes “KotlinException, No transformation found” Seems ktor uses “content-type” from response header to choose deserializer. I tried to override response’s header using interceptor but didn’t work either
Copy code
addInterceptor { chain ->
                val request = chain.request()

                val response = chain.proceed(request)

                val header = response.headers.newBuilder()
                    .add("Content-Type", "application/json")
                    .build()

                response.newBuilder()
                    .headers(header)
                    .build()
            }
c

Cherrio LLC

09/23/2023, 10:47 PM
Why don’t you get the response body as string, then deserialize it???
c

Chrimaeon

09/24/2023, 5:45 PM