On the javascript side I am getting a similar erro...
# ktor
d
On the javascript side I am getting a similar error to someone earlier when using the HttpClient getting
List is empty.", cause_th0jdv$_0: null, name: "NoSuchElementException"
My gradle file has the following
Copy code
compile ("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${LibraryVersions.kotlin_js_serialization_version}")
    compile ("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${LibraryVersions.kotlin_js_serialization_version}")
    compile ("io.ktor:ktor-client-core:${LibraryVersions.ktor_version}")
    compile ("io.ktor:ktor-client-js:${LibraryVersions.ktor_version}")
    compile ("io.ktor:ktor-client-json-js:${LibraryVersions.ktor_version}")
    compile ("io.ktor:ktor-client-serialization-js:${LibraryVersions.ktor_version}")
    compile ("io.ktor:ktor-client-auth-basic-js:${LibraryVersions.ktor_version}")
Has anyone managed to get this working?
e
Hi @Darren Bell, probably you need to add one of client engines in dependencies: https://ktor.io/clients/http-client/engines.html
d
@e5l Thanks for replying. So I have the following
Copy code
val client = HttpClient(Js).config {
            install(JsonFeature)
            followRedirects = false
        }
But I'm still getting the issue that there appears to be no defaultSerializer. Is my configuration incorrect? I'm using version 1.2.1 of ktor, and I'm pretty certain I had this working in a previous version.
👀 1
Also, of note. When I remove the
JsonFeature
, deserialization appears to work as expected. But when I need to serialize an object for a POST, then I get a class cast exception instead. Cheers
After a bit more searching I found the answer:
Copy code
val client = HttpClient(Js).config {
        install(JsonFeature) {
            this.serializer = KotlinxSerializer(Json.nonstrict)
        }
    }
Simple when you know how!