I have two classes where one is nested in the other. I'd like to deserialize and validate incoming JSON against this structure of mine. I have a javax Validator obtained by
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
And later I do:
Set<ConstraintViolation<Object>> validate = validator.validate(obj);
Where obj
is my deserialized JSON. My nested classes are
class Foo {
@Min(5)
Integer a;
List<Bar> bars;
static class Bar {
@Min(2)
Integer b;
}
}
I know that, unless I specify @Valid
annotation on my List<Bar> bars
field, the validator
is not going to make a recursive validation. However, I'd like the default behavior of the validator
to be recursive.
Is there a way to do that when getting the instance of the Validator
?