I am using kotlinx.serialisation and had a question.
I have JSON like this:
{
"state": "bad"
}
state can return bad|good|near_good
My State data class looks like this:
@Serializable
internal enum class State {
@SerialName("good") GOOD,
@SerialName("bad") BAD,
@SerialName("near_good") NEAR_GOOD
}
Is it possible to have the enum names remain all caps like this, while parsing the json value that is returned? Right now when I test this, the parsed json data returns as GOOD|BAD|NEAR_GOOD, because the enum name is uppercase. Hopefully the question makes sense. Appreciate any answers.
EDIT (Updated for clarity)
Right now I have a test that checks: assert(state.name == "bad") This fails because with the way I mentioned it above (@SerialName("bad") BAD), the state.name is equal to 'BAD'. I want the enum name to be uppercase, as per enum naming convention, but I want the value to be lowercase as per the JSON. I can fix the failing test by changing it to be
@SerialName("bad") bad
I'm not sure if it is possible or maybe I am doing something in the wrong way, but I hope this clarifies.
Thanks!