Generating a error code per property in Hibernate validator
Posted
by Mike Q
on Stack Overflow
See other posts from Stack Overflow
or by Mike Q
Published on 2010-04-18T21:02:04Z
Indexed on
2010/04/18
23:23 UTC
Read the original article
Hit count: 345
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.
© Stack Overflow or respective owner