Hello, I'm using kotlinx.serialization, but I used...
# announcements
m
Hello, I'm using kotlinx.serialization, but I used Moshi before to convert JSON to Kotlin classes. However, how can I write to same work with following Moshi's code?
Copy code
override fun fromJson(reader: JsonReader): Volumes? {
    val volumes = mutableListOf<Volume>()

    while (reader.hasNext()) {
        val path = reader.nextName()
        reader.skipValue()
        volumes.add(Volume(path))
    }

    return Volumes(volumes)
}

override fun toJson(writer: JsonWriter, value: Volumes?) {
    if(value == null) return
    writer.beginObject()
    for(volume in value.volumes) {
        writer.name(volume.path)
        writer.beginObject()
        writer.endObject()
    }
    writer.endObject()
}
m
I read, but I couldn't understand to set oridinal name and empty object. Can someone show me a sample in this case?