Hello everyone, Im getting No such element except...
# ktor
s
Hello everyone, Im getting No such element exception - List is empty when changing the configuration of HttpClient in iOS. client = HttpClient().config { expectSuccess = false install(JsonFeature) { serializer = defaultSerializer() } }
t
I just tried this code and it worked fine. i'm using
ktor-client-okhttp
and
ktor-client-gson
on the JVM, maybe your problem comes specifically from the
ktor-client-ios
implementation.
s
yeah it only occurs on iOS
i dont have any problems when running on jvm either
e
Hi @Sergioedcigreja, it’s the known problem. There is no reflection in
kotlin-native
and you have to call
register
method on
KotlinxSerializer
explicitly for now 😞
s
thats interesting, I must be doing something wrong as I cant reference KotlinxSerializer()
s
I already had that dependency on the jvm
commonMain {
dependencies {
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.0-M2'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.11.1"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
implementation kotlin('stdlib')
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-M2'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.1'
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
}
}
jvmTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializer_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutine_version"
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-core-native:$ktor_version"
implementation "io.ktor:ktor-client-json-native:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
}
}
iosTest {
}
e
Could you create a gist(https://gist.github.com)?
s
build.gradle
build.gradle
sure
thank you
e
It looks like
"io.ktor:ktor-client-serialization:$ktor_version"
is missing in
commonMain
. It would be easier to config with gradle metadata enabled.
s
didn't know that dependency existed xD
thank you very much
📝 1
Sorry to bother you again but I'm getting this error kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen exceptions.ErrorResponse@81a0fbd8
Error response is a @Serializable data class
the error occurs at HttpResponse.receive<ErrorResponse>