Kotlinx.serialization: [Help] How to deserialize/parse lists after 1.0?

Created on 30 Nov 2020  路  2Comments  路  Source: Kotlin/kotlinx.serialization

I used to use A.serializer().list to get a list serializer, but this extension is removed after 1.0. And ArrayListSerializer is removed too. Is there a replacement?

Answers in this issue are deprecated: https://github.com/Kotlin/kotlinx.serialization/issues/179

Code:

@Serializable
data class W(val w: String)

val jsonString = """[{"w": "1"}, {"w": "2"}]"""

// Old method:
val obj = json.parse(W.serializer().list, jsonString)
question

Most helpful comment

Yes, ListSerializer() is a correct replacement for list extension.

All 2 comments

Have you tried this:
val obj = json.decodeFromString(ListSerializer(W.serializer()), jsonString)

Yes, ListSerializer() is a correct replacement for list extension.

Was this page helpful?
0 / 5 - 0 ratings