and then defining a default value. The downside to that is that you need to remember to set the default in all serializable classes using the enum.
Copy code
val format = Json { coerceInputValues = true }
enum class Foo { Bar, Baz, Unknown }
@Serializable
data class Project(val name: String, val language: String = "Kotlin", val foo: Foo = Foo.Unknown)
fun main() {
val data = format.decodeFromString<Project>(""" {"name":"kotlinx.serialization","language":null, "foo": "bao" } """)
println(data) // $ Project(name=kotlinx.serialization, language=Kotlin, foo=Unknown)
}