I'm trying to map enum to int values:
@Serializable
enum class ItemType {
@SerialName("0") Zero,
@SerialName("1") First,
}
But it fails with the following exception:
JsonDecodingException: Unexpected JSON token at offset 194: Expected quotation mark '"', but had '1' instead
JSON input: ....."type":1,.....
It doesn't seem to work because
SerialName
is expecting a string and json has an int.
I can think of two ways to solve this:
1. Enabling lenient mode - I don't like this solution as it also removes restrictions from other fields, which I prefer to keep
2. Implementing a custom serializer - seems like too much of boilerplate code for such a simple task
Am I missing something?