Hi All,
Testing a class level constraint, though it seems working fine but getting issue while displaying errors to the user end.here is my constraints declaration
Code:
@Constraint(validatedBy = FieldMatchValidator.class)
@Documented
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
public @interface FieldMatch
{
String message() default "Fields are not matching";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
/**
* @return The first field
*/
String first();
/**
* @return The second field
*/
String second();
/**
* Defines several <code>@FieldMatch</code> annotations on the same element
*
* @see FieldMatch
*/
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Documented
@interface List
{
FieldMatch[] value();
}
Its implementation is also working fine, but i need to check which is class level violation and which method level violation and here is my piece of code
Code:
protected boolean isActionError(ConstraintViolation<Object> violation) {
if(violation.getPropertyPath().iterator().next().getName() == null){
return true;
}
return false;
}
But in my case
Code:
violation.getPropertyPath().iterator().next().getName()
is not null and it seems either i misunderstood violation.getPropertyPath() or something is not working as expected.
can anyone help me as where i am doing wrong