CLOVIS
03/06/2020, 11:21 AM/account/auth/
) which I should send a JSON object to, which contains a field username
and a field password
. It should return a JSON object that contains a token
field.
I want to use Kotlinx.Serialization to generate the JSON objects, so I started with:
@Serializable
private data class ApiUsernamePassword(val username: String, val password: String)
and I do my request like this:
val client = HttpClient() {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
val res = <http://client.post|client.post><String> {
url("<http://localhost:8000/account/auth/>")
body = ApiUsernamePassword(username, password)
}
On the JVM, I get this error:
Companion
java.lang.NoSuchFieldError: Companion
at io.ktor.client.features.json.serializer.KotlinxSerializer.<init>(KotlinxSerializer.kt:22)
(I can send the full stacktrace if needed)
On JS, I get this error:
TypeError: Cannot read property 'plain' of undefined
at new KotlinxSerializer (<http://localhost:9876/absolute/[REDACTED]/adapter-browser.js?fb6a5f1e12e8cc2bf794189b2b55f22def38ca94:157371:29>)
I've tried Googling it but I don't get any meaningul/related results for both of those errors... Did anyone encounter this before? I also tried adding an empty companion object to my serializable class but it didn't change anything. (all of the above is in the common module, if that's relevant)gabin
03/06/2020, 11:39 AMCLOVIS
03/06/2020, 11:40 AMgabin
03/06/2020, 11:42 AMCLOVIS
03/06/2020, 11:44 AMFail to send body. Content has type: class net.wildfyre.lib.ApiUsernamePassword (Kotlin reflection is not available), but OutgoingContent expected.
ribesg
03/06/2020, 11:57 AMcontentType(ContentType.Application.Json)
before body = …
CLOVIS
03/06/2020, 1:23 PM