{"id":1372,"date":"2012-05-27T15:51:58","date_gmt":"2012-05-27T20:51:58","guid":{"rendered":"http:\/\/unitstep.net\/?p=1372"},"modified":"2012-05-27T15:51:58","modified_gmt":"2012-05-27T20:51:58","slug":"jax-rsjersey-needs-an-required-annotation-for-parameters","status":"publish","type":"post","link":"https:\/\/unitstep.net\/blog\/2012\/05\/27\/jax-rsjersey-needs-an-required-annotation-for-parameters\/","title":{"rendered":"JAX-RS\/Jersey needs an @Required annotation for parameters"},"content":{"rendered":"

I’ve been using Jersey as a JAX-RS implementation for a little while now, and one thing that it could benefit from is the addition of an @Required<\/code> annotation for resource method parameters. Right now, when parameters are not provided by the client\/request, they are simply set to null<\/code>, creating the need for duplicated null-checking in resource methods. An @Required<\/code> annotation would solve this issue and reduce code duplication.<\/p>\n

This isn’t so much of an issue for @PathParam<\/code> parameters, (since you won’t even get to the proper resource method without a matching URI) but it does affect @HeaderParam<\/code> and @QueryParam<\/code> (among others) since they aren’t needed for Jersey to determine which resource method to invoke. By that definition, they are implicitly optional. There should be a way to make them required.<\/p>\n

The behaviour of such a required annotation might be as follows:<\/p>\n