I have a class in kotlin which is an enum class as below
enum class Status {
@SerializedName("open")
OPEN,
@SerializedName("close")
CLOSE,
UNKNOWN
}
I have another class called ticket using the status enum class
class Order(
var id: String,
var status: Status = Status.UNKNOWN,
}
When the GSON map the value received, I have an exception because the status field now contains a new value in_progress. As this state is not declared in the Status class, the exception happened.
How can I avoid the exception to make sure that if a new status is set in the GSON but not defined in the Status class, I got status UNKNOWN?
Any idea on how to return a default value UNKNOWN in my case when nothing match ?
Thanks