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

Sergioedcigreja

07/03/2019, 10:48 AM
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

tseisel

07/03/2019, 11:46 AM
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

Sergioedcigreja

07/03/2019, 11:47 AM
yeah it only occurs on iOS
i dont have any problems when running on jvm either
e

e5l

07/03/2019, 11:50 AM
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

Sergioedcigreja

07/03/2019, 12:00 PM
thats interesting, I must be doing something wrong as I cant reference KotlinxSerializer()
s

Sergioedcigreja

07/03/2019, 12:05 PM
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

e5l

07/03/2019, 12:08 PM
Could you create a gist(https://gist.github.com)?
s

Sergioedcigreja

07/03/2019, 12:08 PM
build.gradle
build.gradle
sure
thank you
e

e5l

07/03/2019, 12:11 PM
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

Sergioedcigreja

07/03/2019, 12:13 PM
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>
2 Views