Mario Andhika
10/07/2024, 7:06 AMenum class StatusAffiliate{
deleted,
active,
}
As you can see, the enum names are in lowercase for compatibility with current DB values. But I want it more like this if there’s a way:
enum class StatusAffiliate{
@SerialName("deleted") Deleted,
@SerialName("active") Active,
}
Oleg Babichev
10/07/2024, 9:56 AMenumerationByName
doesn't support such an option, it just takes the names of the enum values as keys of the map (enumConstants by lazy { klass.java.enumConstants!!.associateBy { it.name } }
- the part of EnumerationNameColumnType
class)
I'd say you have to use customEnumeration
for your case with the current api.
It could write something like this at the first glance:
enum class StatusAffiliate(val tableName: String) {
Deleted("deleted"),
Active("active"),
}
object TestCustomEnumTable : IntIdTable() {
val value = customEnumeration(
"value", "status_affiliate",
fromDb = { value ->
when (value) {
is String -> StatusAffiliate.entries.find { it.tableName == value } ?: error("Enum value does not exists")
else -> error("The value from DB is not string")
}
},
toDb = { it.tableName}
)
}