kotlinx.serialization: Can't locate companion serializer for class class List
The documentation mentiones that serializing lists is supported, but I can’t seem to get it working.
When running this code in Kotlin-JS:
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JSON
fun main(args: Array<String>) {
val list = listOf(Foo("a"), Foo("b"))
println(JSON.stringify(list))
}
@Serializable
data class Foo(val foo: String?)
I get the exception SerializationException "Can't locate companion serializer for class class List". I’m using Kotlin version 1.1.50 and kotlinx.serialization version 0.2.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (11 by maintainers)
this one working: val map = mapOf(1 to “1”, 2 to “2”) val serial = (IntSerializer to StringSerializer).map val s = JSON.unquoted.stringify(serial, map) assertEquals(“{1:1,2:2}”,s) but not this: val map23 = mapOf(1 to mapOf(3 to “4”), 2 to mapOf(4 to “5”)) val serial = (IntSerializer to StringSerializer).map val s = JSON.stringify(serial, map23)
is it possible to serialize nested maps?