Add support for enum-based map keys
Im getting this error: Caused by: java.lang.UnsupportedOperationException: map key must be a non-nullable string full error: https://pastebin.com/AAD74gky
my data class looks like this
@Serializable data class Config( val map: MutableMap<ExplosionType, Boolean>, ) : Validatable
ExplosionType is an enum
but if I do this: val map: MutableMap<ExplosionType?, Boolean?>, it works again
I saw this bug on github, maybe updating kotlinx.serialization to 1.5.0 can fix the bug (https://github.com/Kotlin/kotlinx.serialization/pull/2176)
For example this code will preduce an error https://pasteboard.co/PYioYh4KXi8b.png
At the time being, this is actually the expected behavior.
From a JSON5 point of view, object keys (officially referred to as JSON5MemberName) are non-nullable strings, either in the form of an unquoted identifier or in the form of a quoted string literal (see here).
I would argue that even for simple types such as Map<String?, Int>, parsing JSON5 text can be ambiguous. For example, how shall the text {null: 100} be parsed? Does the key refer to an absent value or null as a string literal?
Accepting certain primitives (such as floating-point numbers) can be difficult as well. For example, keep in mind that for the Float data type, all decimal numbers from 1.99999983 to 1.99999994 actually refer to the very same value. How would you handle a case in which multiple such values appear as keys? Shall they be treated as duplicates?
Unfortunately, the library is often unable to detect that such map keys are part of the data model until a prohibited value appears. Then, however, an UnsupportedOperationException will be raised.
The only type for which I see an intuitive one-to-one mapping to strings are non-nullable enum values. During my attempt to implement this feature, I ran into this issue, which I am currently not sure how to handle from the perspective of json5k. As soon as this is resolved, I am happy to add enum key support to the library.