Nikita Khlebushkin
08/14/2021, 10:35 PMW/System.err: kotlinx.serialization.SerializationException: Serializer for class 'Companion' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
The place I am trying to use:
try {
api.createAccount(Account(handle = "some", displayname = "Some name"))
} catch (e: Exception) {
e.printStackTrace()
}
And the class itself:
import kotlinx.serialization.Serializable
@Serializable
data class Account(val handle: String, val displayname: String)
Ktor's HttpClient config contains:
install(JsonFeature) {
serializer = KotlinxSerializer(Json {
ignoreUnknownKeys = true
encodeDefaults = true
useAlternativeNames = false
})
}
In my build.gradle.kts of the module I have:
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.squareup.sqldelight")
id("com.android.library")
}
kotlin {
...
sourceSets {
val serializationVersion = "1.2.2"
val ktorVersion = "1.6.2"
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
}
}
What am I doing wrong?Nikita Khlebushkin
08/15/2021, 12:06 AMAccount
class but on deserializing the response, so the issue is closed