ignoreUnknownKeys
Specifies whether encounters of unknown properties in the input JSON should be ignored instead of throwing SerializationException. false
by default.
Example of usage:
@Serializable
data class Project(val name: String)
val withUnknownKeys = Json { ignoreUnknownKeys = true }
// Project(name=unknown), "version" is ignored completely
println(withUnknownKeys.decodeFromString<Project>("""{"name":"unknown", "version": 2.0}"""))
// Fails with "Encountered an unknown key 'version'"
Json.decodeFromString<Project>("""{"name":"unknown", "version": 2.0}""")
Content copied to clipboard