Performing validation

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:

  1. 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;
  2. Add a final member, validator, and update the constructor method in order to initialize it.
    private final ContactDAO contactDao; private final Validator ...

Get RESTful Web Services with Dropwizard now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.