Generating a error code per property in Hibernate validator
- by Mike Q
Hi all,
I am looking at using hibernate validator for a requirement of mine. I want to validate a bean where properties may have multiple validation checks. e.g.
class MyValidationBean
{
@NotNull
@Length( min = 5, max = 10 )
private String myProperty;
}
But if this property fails validation I want a specific error code to be associated with the ConstraintViolation, regardless of whether it failed because of @Required or @Length, although I would like to preserve the error message.
class MyValidationBean
{
@NotNull
@Length( min = 5, max = 10 )
@ErrorCode( "1234" )
private String myProperty;
}
Something like the above would be good but it doesn't have to be structured exactly like that. I can't see a way to do this with hibernate validator. Is it possible?
Thanks.