decodeEnumsCaseInsensitive

Enables decoding enum values in a case-insensitive manner. Encoding is not affected by this option.

It affects both enum serial names and alternative names (specified with the JsonNames annotation). Example of usage:

enum class E { VALUE_A, @JsonNames("ALTERNATIVE") VALUE_B }

@Serializable
data class Outer(val enums: List<E>)

val json = Json { decodeEnumsCaseInsensitive = true }
// Prints [VALUE_A, VALUE_B]
println(json.decodeFromString<Outer>("""{"enums":["Value_A", "alternative"]}""").enums)
// Will fail with SerializationException: no such enum as 'Value_A'
Json.decodeFromString<Outer>("""{"enums":["Value_A", "alternative"]}""")

With this feature enabled, it is no longer possible to decode enum values that have the same name in a lowercase form. The following code will throw a serialization exception:

enum class CaseSensitiveEnum { One, ONE }
val json = Json { decodeEnumsCaseInsensitive = true }
// Fails with SerializationException: The suggested name 'one' for enum value ONE is already one of the names for enum value One
json.decodeFromString<CaseSensitiveEnum>("ONE")