https://kotlinlang.org logo
#serialization
Title
# serialization
k

Karlo Lozovina

04/28/2021, 5:45 PM
This looks to be the minimal example to trigger this (using kotlin 1.5 RC, and serializatoin plugin 1.5 RC):
Copy code
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.decodeFromString


@Serializable
inline class Name(val b: String)

@Serializable
sealed class Pet {
    @Serializable
    @SerialName("dog")
    data class Dog(val name: Name) : Pet()
}


fun main() {
    val jsonString = """
        {
            "type": "dog",
            "name": "Rufus"
        }
    """.trimIndent()
    val dog = Json.decodeFromString<Pet>(jsonString)
    println(dog)
}
🧵 1