Hibernate validator - conditionally apply validator

I want to apply certain @NotBlank annotations only if the other field is false. In my current project, we must use a sleep mode validator, so there’s no validation of general accessibility + valang to solve this problem.

Since I'm not too fond of creating a few custom annotations to decide what should be easy (bit, bumped, that this is not included in the JSR-303 specification). I was wondering if anyone knows an acceptable way to do this. I found a jar that did this, but it was for sleep mode 3. And because of the changes ...

+5
source share
1 answer

In this case, the proposed approach is to use class level restrictions instead of a field or property level.

Please refer to Hibernate Validator Documents

Now I'm annoying. I had such a scenario and I tried something like @NotEmpty (depend = "anotherField"), and it was a complete failure.

Perhaps some other members know another way to do this, but for now I am doing what the Hibernate Validator says.

+5
source

All Articles