I read many tutorials about JSR 303 spec, but I don't see any example ready for production. Everywhere described how to get Set<Constraintviolation<T>>
object.
Example:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Set<ConstraintViolation<Car>> violations = validator.validate(car);
But what next? I want to inform method caller (client) that method parameter is in inconsistent state.
What I must do with Set<ConstraintViolation<Car>>
? I need manually iterate over Set<ConstraintViolation>
, collecting all error messages into one string, and then throw an exception with this messages?
Or exist some more convenient ways out of the box?
Or it's better to provide validate
method inside each bean?