How can I serialize class with set of class by `ko...
# ktor
a
How can I serialize class with set of class by
kotlinx-serialization
in 1.3.0? I have
kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class DeviceItems
All examples for older versions
Copy code
@Serializable
data class DeviceItems(val id: String, val rows: Set<DeviceItem>)
s
Is
DeviceItem
annotated with Serializable?
a
Yes.
Copy code
@Serializable
data class DeviceItem(val appPackage: String, ... ): BaseItem()

@Serializable
abstract class BaseItem { val timestamp: Long = currentTimestamp }
Maybe it’s important class
BaseItem
is a superclass for all classes.
Copy code
@Serializable
data class DeviceItems(val id: String, val rows: Set<DeviceItem>): BaseItem()
And I have the same problem with class
Copy code
import kotlinx.serialization.Serializable

@Serializable
data class SystemInfo(val platform: String, val sdkVersion: String)
s
Oh, no idea then...
a
Maybe i’ve made a mistake in configuration file? root build.gradle.kts
Copy code
plugins {
    kotlin("multiplatform") version "1.3.72"
    id("kotlinx-serialization") version "1.3.72"
}
...
root settings.gradle.kts
Copy code
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlinx-serialization") {
                useModule("org.jetbrains.kotlin:kotlin-serialization:${requested.version}")
            }
        }
    }
...
module build.gradle.kts
Copy code
val ktorVersion = "1.3.2"
        commonMain {
            dependencies {
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-json:$ktorVersion")
                implementation("io.ktor:ktor-client-serialization:$ktorVersion")
...
        macosMain { 
            dependencies {
                implementation("io.ktor:ktor-client-curl:$ktorVersion")
                implementation("io.ktor:ktor-client-core-native:$ktorVersion")
                implementation("io.ktor:ktor-client-json-native:$ktorVersion")
                implementation("io.ktor:ktor-client-serialization-native:$ktorVersion")
            }
        }
It’s ok?
@SerVB 1. Why
kotlinx-serialization
plugin must be version 1.3.72, not 1.3.2? 2. Why I can’t define plugin by
kotlin("kotlinx-serialization") version "1.3.72"
and have to write
id("kotlinx-serialization") version "1.3.72"
?
s
I'm not sure how to use kx.serialization in ktor, but I've used it standalone. And it requires another plugin, not
id("kotlinx-serialization") version "1.3.72"
, but
kotlin("plugin.serialization") version "1.3.70"
, as described here: https://github.com/Kotlin/kotlinx.serialization#gradle
t
Here is my sample repo with using kotlinx.serialization. https://github.com/morin128/ktor-http-api/blob/master/src/models/Order.kt And i’m using the versions below. ktor : 1.3.2 kotlin : 1.3.70