We've just defined what a valid annotation is. Now, we must modify the code of our resource class in order to verify that each POST and PUT request contains a valid
Contact object, based on which a contact is created or updated.
How to do it…
Let's see what needs to be modified in our resource class by performing the following steps:
- First, we need to import some classes that will help us with the validation.
import java.util.Set; import javax.validation.ConstraintViolation; import javax.util.ArrayList; import javax.validation.Validator; import javax.ws.rs.core.Response.Status;
- Add a final member,
validator, and update the constructor method in order to initialize it.
private final ContactDAO contactDao; private final Validator ...