I am writing a REST API with a Java/Jersey/Jackson stack. All JSON parsing and generating is done with Jackson. The REST layer is handled by Jersey. It will be embedded in a Grizzly container.
In my API, I accept JSON in my endpoints. For example:
@POST
public Response post(final SomeObject input) {
return ...;
}
What is the best way to validate the input
? There are certain things I would like to validate:
input
must be not null- certain fields of
input
must be not null - certain fields of
input
must follow a regular expression (text fields) - certain fields of
input
must be in a range (numeric fields) - ...
If possible, I would like to change my code as less as possible. That is, I prefer to annotate my classes, methods and parameters to integrate the validation.