Enum in Kotlin

const val START_ACTION = “start”

enum class Actions(val info: String) {
START(START_ACTION)
}

@Serializable
data class ActionRequest(
@SerialName(“action_type”). —> backend datatype
val actionType: Actions. ----> enum is compulsory to use here
)

val actionRequest = ActionRequest(actionType = START)

Here, I am getting output is “START” rather than “start”.

Can someone please help me with how to get the value of action?

You can do it like this:

@Serializable
enum class Actions(val info: String) {
    @SerialName(START_ACTION) START(START_ACTION)
}

You can remove info property if you planned to use it solely for serialization purposes.

Thank you.
For the fixing the above issue, I need to use a custom Serializer.
This issue is fixed now

1 Like