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

aleksey.tomin

06/01/2020, 1:02 PM
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

SerVB

06/01/2020, 1:32 PM
Is
DeviceItem
annotated with Serializable?
a

aleksey.tomin

06/01/2020, 4:38 PM
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

SerVB

06/01/2020, 6:54 PM
Oh, no idea then...
a

aleksey.tomin

06/01/2020, 7:13 PM
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

SerVB

06/01/2020, 9:14 PM
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

Takashi

06/02/2020, 1:01 AM
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
5 Views