Ktor Version and Engine Used (client or server and name)
1.3.0, client, ktor-client-json
Describe the bug
I'm trying to write a simple rest api client with json serialisation as my first kotlin multiplatform project. I managed to use ktor http client and execute it on both android and ios, but I'm failing trying to add json support. The error I got on simulator execution (top part of it):
Uncaught Kotlin exception: kotlin.NoSuchElementException: List is empty.
at 0 SharedCode 0x0000000105070377 kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable + 87
at 1 SharedCode 0x0000000105069b05 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85
at 2 SharedCode 0x00000001050696c5 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85
at 3 SharedCode 0x0000000105069865 kfun:kotlin.NoSuchElementException.<init>(kotlin.String?)kotlin.NoSuchElementException + 85
at 4 SharedCode 0x000000010503b1b1 kfun:[email protected]<#GENERIC>.()Generic + 337
at 5 SharedCode 0x000000010530584e kfun:io.ktor.client.features.json.defaultSerializer()io.ktor.client.features.json.JsonSerializer + 142
at 6 SharedCode 0x000000010530229c kfun:io.ktor.client.features.json.JsonFeature.Feature.prepare(kotlin.Function1<io.ktor.client.features.json.JsonFeature.Config,kotlin.Unit>)io.ktor.client.features.json.JsonFeature + 588
at 7 SharedCode 0x00000001052cd9f3 kfun:io.ktor.client.HttpClientConfig.install$<anonymous>_1#internal.273 + 883
at 8 SharedCode 0x00000001052cdf89 kfun:io.ktor.client.HttpClientConfig.$install$<anonymous>_1$FUNCTION_REFERENCE$16.invoke#internal + 89
at 9 SharedCode 0x00000001052ce009 kfun:io.ktor.client.HttpClientConfig.$install$<anonymous>_1$FUNCTION_REFERENCE$16.$<bridge-UNNN>invoke(#GENERIC)#internal + 89
at 10 SharedCode 0x00000001052ccbd7 kfun:io.ktor.client.HttpClientConfig.install(io.ktor.client.HttpClient) + 775
I realised it probably cannot work because it seems like ktor-client-json has no target for ios:
The documentation is very sparse, I assumed it's available. So what's the status and what can I expect when it comes to multiplatform support in ktor?
This is because you have no serialization support dependency, e.g. io.ktor:ktor-client-serialization-native for native targets
Hi @kar, thanks for the report.
As @cy6erGn0m mentioned, the native JSON feature has a separate artifact name.
Here is the documentation about JSON feature configuration: https://ktor.io/clients/http-client/features/json-feature.html