klaxon icon indicating copy to clipboard operation
klaxon copied to clipboard

Serialing Enum values with their own anonymous classes throws IllegalArgumentException("Could not find associated enum field for $value")

Open stpeev opened this issue 4 years ago • 2 comments

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.

stpeev avatar Jun 13 '20 12:06 stpeev

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.

stpeev avatar Aug 21 '20 14:08 stpeev

I am sorry you are completely correct. Deleted my comment. Did not realize I was using such an old version.

mdres avatar Aug 24 '20 06:08 mdres