we have create this enum for code readability and we don't have direct control over how server is returning constants for the user roles, so they have done it this way 'U' , R etc
apiRespose.role = "U"
Role.valueOf(apiResponse.role) will not work ,as it is expecting 'APPROVER' as input . How can i achieve same benefit of Role.valueOf( ) wrt ot the 'letter' attribute in the enum
c
Chris
08/13/2021, 1:26 PM
Copy code
enum class Role(val letter: Char) {
APPROVER('U'),
ADMIN('D'),
INQUIRER('R'),
OPERATOR('O');
companion object {
fun from(letter: Char) = values().find { it.letter == letter }
}
}
and use it like
Role.from(letter)
Is this what you’re after?
h
hho
08/13/2021, 1:32 PM
Please don't crosspost. See my answer in #C0B8MA7FA
c
Chris
08/13/2021, 1:36 PM
Agreed. (although this had the Q and A before the other channel)
👍 1
a
althaf
08/13/2021, 1:38 PM
@hho sorry, i did that , as last message from the moderator mentioned #C0922A726 is no longer QA. I read the message from the moderator only after posting this. So , i posted to this #C0B8MA7FA channel . Sorry for crossposting.