https://kotlinlang.org logo
Title
v

veiset

09/18/2018, 10:20 AM
I need to annotate the
name
field of an enum. Any ideas how to do that? We are using a validation framework that is pretty strict and wont accept
ENUM_NAME
(underscore) from frontend, so I need to annotate the
name
-field of an enum to loosen up the validation.
g

gildor

09/18/2018, 10:23 AM
I’m not completely sure, but you probably cannot. How you can do that in Java for example
v

veiset

09/18/2018, 10:25 AM
In java
name
is a method, so it wont be validated, while in kotlin its a field.
g

gildor

09/18/2018, 10:26 AM
But why do you want annotate it? How do you serialize enum?
v

veiset

09/18/2018, 10:30 AM
The framework is checking all public fields and validating them. The way this is solved in our own DTOs is that we annotate the fields telling the validator which level of strictness we want on that field. The problem is that the public field
name
in a kotlin enum is validated and I have no way to tell the validator how it should validate it. I'll try to take another approach in solving this.