klaxon
klaxon copied to clipboard
Serialing Enum values with their own anonymous classes throws IllegalArgumentException("Could not find associated enum field for $value")
As per Kotlin documentation you can define enum constants with their own anonymous classes https://kotlinlang.org/docs/reference/enum-classes.html#anonymous-classes
enum class ProtocolState { WAITING { override fun signal() = TALKING }, TALKING { override fun signal() = WAITING }; abstract fun signal(): ProtocolState }
still if you try to serialize a class containing such enum value, e.g.
class Klass { val ProtocolState state = WAITING; }
You get back IllegalArgumentException("Could not find associated enum field for $value")
The following change introduce the issue: https://github.com/cbeust/klaxon/commit/16ae9bb39486dfaa992ea694dd85634b39e515fa#diff-e2f35f675a9eeae1e1e705dc6527dc15. It simply seems not to consider the possibility to have anonymous classes with enum constants.
Pay attention to the link in the original post. The code in question goes into v5.0.13 and later. Trying out with 5.0.1 proves nothing.
I am sorry you are completely correct. Deleted my comment. Did not realize I was using such an old version.