[Jersey] How to catch the response in case of an invalid query paramter

From: Pengfei Di <>
Date: Thu, 14 Apr 2011 12:42:57 +0200


I have a very simple GET REST API, which returns something only based on
the query parameter. For example:
public MyClass getSomething ( @QueryParam("age") Integer age);

As listed above, I specify the parameter type as Integer. However,
problem occurs when the given parameter cannot be parse to an integer.
For an instance: if the parameter is set as "age=one" instead of
"age=1", Jersey server will say "HTTP status 404 - Not Found."

What I want to do is to specify the response by myself, but I have no
idea where I can do it. Shouldn't Jersey throw an
NumberFormatException. In fact, it doesn't. :(

Thanks for any hint