How to check value against enum? #80
Answered
by
dhoepelman
vishwas-trivedi
asked this question in
Q&A
-
I have a enum(string) in the request body and I want to check value in request body is any value in enum or not.
Enum
Is there any way to validate |
Beta Was this translation helpful? Give feedback.
Answered by
dhoepelman
Apr 1, 2024
Replies: 1 comment
-
Yes, you can add any constraint you want: enum class UserType {
GENERAL, ADMIN, SUPER_ADMIN;
companion object {
val validStrings: Set<String> = entries.map { it.name }.toSet()
}
}
data::type {
addConstraint("{value} must be on of ${UserType.validStrings}") { it in UserType.validStrings }
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dhoepelman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you can add any constraint you want: