In Hibernate Validator, we can validate an object either by @Valid
, or by directly calling up a Validator instance
Validator validator = Validation.buildDefaultValidatorFactory().getValidator()
and do a validator.validate(myObject)
to validate it. If I already separate the constraints on the object into different groups, I can do a validator.validate(myObject, myGroup.class)
to validate only the constraints in my group.
Is there any way to use a Validator instance to validate only one constraint, without using groups?
Background
I am using Hibernate Validator to validate various objects at a Spring Controller. It looks like Collection<Object>
parameters in controller methods do not do cascaded validation, because Spring AbstractMessageConverterMethodArgumentResolver
does validation by using a Validator instance. Since the annotation Collection<@Valid Object>
is not working, I am trying to see if there is any way I can validate each object in the collection.
Thank you!