'io.ktor.client.call.NoTransformationFoundExceptio...
# ktor
p
'io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> interface java.util.List (Kotlin reflection is not available) with response from https://cmms.auswegprime.com/Api/get_plant_engineer_status_list: status: 200 ' I get this error while receiving data from server
j
Are you running on graal (answered no)
Can you share the stack trace?
p
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> interface java.util.List (Kotlin reflection is not available) with response from https://cmms.auswegprime.com/Api/get_plant_engineer_status_list: status: 200 response headers: cache-control: no-store, no-cache, must-revalidate , content-type: text/html; charset=UTF-8 , date: Tue, 04 Jul 2023 122744 GMT , expires: Thu, 19 Nov 1981 085200 GMT , pragma: no-cache , server: Apache/2.4.54 () PHP/7.4.32 , set-cookie: ci_session=kqp50i5khd1fqpbgqqjqjochah0bg088; expires=Tue, 04-Jul-2023 142744 GMT; Max-Age=7200; path=/; HttpOnly , x-powered-by: PHP/7.4.32 2023-07-04 175727.829 25626-25830 ProfileInstaller org.mdeveloperz.estore.android D Installing profile for org.mdeveloperz.estore.android 2023-07-04 175754.850 25626-25645 System org.mdeveloperz.estore.android W A resource failed to call close.
a
The problem is that the endpoint replies with the
Content-Type: text/html; charset=UTF-8
instead of the expected
Content-Type: application/json
.
j
I do really not understand that stack trace
Not a lot of tracing going on in there
p
how to handle this one?@Aleksei Tirman
j
respond(contentType = ContentType.Application.Json)
p
Copy code
//@Composable
//fun ProductListView() {
//    val scope = rememberCoroutineScope()
//    var products by remember {
//        mutableStateOf(emptyList<engineer_status>())
//    }
//    val context = LocalContext.current
//    LaunchedEffect(true) {
//        scope.runCatching {
//            GetProductsUseCase().execute(Unit)
//        }.onSuccess { remoteProducts ->
//            Toast.makeText(context, "tag1$remoteProducts", Toast.LENGTH_SHORT).show()
//
//            if (remoteProducts.isEmpty()){
//                products = remoteProducts
//            }else{
//                Toast.makeText(context, "tag2$remoteProducts", Toast.LENGTH_SHORT).show()
//            }
//        }.onFailure {
//            Log.d("Failed", "Network error$it")
//        }
//    }
//
//    Scaffold(topBar = {
//        TopAppBar {
//            Row(modifier = Modifier.padding(10.dp)) {
//                Text(text = "Products")
//            }
//        }
//    }) { defaultPadding ->
//        LazyColumn(modifier = Modifier.padding(defaultPadding)) {
            items(products) { product ->
          ProductItemView(product)
       }
      }
    }
}
this is my full code of calling API using Ktor
where I do the mistake can you explain this one?
a
The server you're making a request to is misconfigured. As a workaround, you can register a JSON converter for the
text/html
content type:
Copy code
HttpClient() {
    install(ContentNegotiation) {
        register(ContentType.Text.Html, KotlinxSerializationConverter(Json))
    }
}
p
where put this code?
a
Where the HTTP client initialization is located.
p
am using for this KMM project. so, i initialize two times one for android. and, another one for IOS
Copy code
class GetProductsUseCase: BaseUseCase<Unit, List<engineer_status>>() {
    override suspend fun execute(request: Unit): List<engineer_status> {
        val response = <http://networkClient.post|networkClient.post>("<https://cmms.auswegprime.com/Api/get_plant_engineer_status_list>")
        return response.body()
    }
}
this is the commanMain http client initialization
Copy code
actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(OkHttp) {
    config(this)

    engine {
        config {
            retryOnConnectionFailure(true)
            connectTimeout(0, TimeUnit.SECONDS)
        }
    }
}
this is for android
a
Find the place where the
ContentNegotiation
plugin is installed.
p
Copy code
expect fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient

val networkClient: HttpClient = httpClient {
    install(ContentNegotiation) {
        json(Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true
        })
    }
}
Here
a
Put the following line inside the install block of the
ContentNegotiation
plugin:
Copy code
register(ContentType.Text.Html, KotlinxSerializationConverter(Json))
p
i added ur code inside of install block. but, i get this error Network errorio.ktor.serialization.JsonConvertException: Illegal input
io.ktor.serialization.JsonConvertException: Illegal input this is the right error
a
There should be a more detailed error message
p
Copy code
expect fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient

val networkClient: HttpClient = httpClient {
    install(ContentNegotiation) {

        json(Json {
            
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true
            register(ContentType.Text.Html, KotlinxSerializationConverter(Json))
        })
    }
}
this is the code. and, the error is io.ktor.serialization.JsonConvertException: Illegal input
a
You need to put your configuration of the
Json { ... }
instead of just
Json
from my example.
It should be
Copy code
val networkClient: HttpClient = httpClient {
    install(ContentNegotiation) {
        register(ContentType.Text.Html, KotlinxSerializationConverter(Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true

        }))
        json(Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true
        })
    }
}
p
Copy code
i put this code 
val networkClient: HttpClient = httpClient {
    install(ContentNegotiation) {
        register(ContentType.Text.Html, KotlinxSerializationConverter(Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true

        }))
        json(Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true
        })
    }
}
again i get this error io.ktor.serialization.JsonConvertException: Illegal input
a
There should be a more detailed error message about what is exactly wrong with the input.
What version of Ktor do you use?
l
@Praveen Kumar @Aleksei Tirman [JB] Hey đź‘‹ Finally, what was the solution, because I currently have the same problem. When I run with my localhost (10.0.2.2), it works But as soon as I point the URL of the hosted server, I have the same error as you Napier Error Client Post : No transformation found: class io.ktor.utils.io.ByteBufferChannel
Copy code
ktorVersion = "2.3.2"
831 Views