Reputation: 17
How can I validate the below class using validator (JSR303) API? This should be done using Hibernate Validator API.
Suppose TesterBatters
class itself has some validation. How can I validate those?
public class Example {
private String jseId;
private String jseType;
private String jseName;
private Double jsePpu;
private TesterBatters jseBatters;
private List<TesterToppin> jseTopping;
public String getTesterId() {
return jseId;
}
}
Upvotes: 1
Views: 1554
Reputation: 18990
You basically have to add constraint annotations such as @NotNull
, @Size
etc. to the elements of your model (i.e. the properties and/or classes) and perform a validation of these constraints at a suitable point of time (e.g. when persisting objects or processing data entered by the user into a GUI) using the javax.validation.Validator
API.
To recursively apply a validation to referenced objects, use the @Valid
annotation.
I recommend to have a look into the Hibernate Validator reference guide which explains in detail how to work with Bean Validation.
Upvotes: 4