If you annotate any Element with @AssertTrue annotation, then the annotated element must be true.
What are the supported types?
a. boolean
b. Boolean
Where can I apply this annotation?
a. METHOD,
b. FIELD,
c. ANNOTATION_TYPE,
d. CONSTRUCTOR,
e. PARAMETER,
f. TYPE_USE
Find the below working application.
package com.sample.model;
import javax.validation.constraints.AssertTrue;
public class Employee {
private int id;
@AssertTrue
private boolean isExperienced;
public Employee(int id, boolean isExperienced) {
this.id = id;
this.isExperienced = isExperienced;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public boolean isExperienced() {
return isExperienced;
}
public void setExperienced(boolean isExperienced) {
this.isExperienced = isExperienced;
}
}
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here