Java Reference
In-Depth Information
group. The following code shows the changes that should be added on the Address
attribute of the Student class in order to take advantage of the group conversion
feature:
@Valid//To propagate the validation of a
student object
@ConvertGroup(from=Default.class,
to=AddressCheck.class)
private Address address;
The following code shows the joint validation attributes of the Student object and
attributesofthe Address objectafterusingthe @ConvertGroup annotation.Asyou
can see in the following code, we did not have to list all the groups of constraints.
Student student = new Student();
student.setId("ST23576");
student.setFirstname("Stelba");
student.setLastname("estelle");
student.setAddress(new Address());
Set<ConstraintViolation<Student>>
constraintViolations
=validator.validate(student);
assertEquals(2, constraintViolations.size());
The following code shows how to use the @ConvertGroup.List annotation:
//annotation
@ConvertGroup.List({
@ConvertGroup(from = Default.class, to =
Citizen.class),
@ConvertGroup(from = Salaried.class, to =
Foreign.class)
})
List<Student> studentList;
Search WWH ::




Custom Search