users@jersey.java.net

[Jersey] How to catch exceptions thrown when deserializing JSON

From: <jeff.sabin_at_gmail.com>
Date: Wed, 3 Oct 2012 16:52:56 +0000 (GMT)

I have a resource that is using the Jackson deserialization to convert
JSON to an object like this:

@POST
@Path ("/foobar")
public Response add(Foo aFoo)
{
   ....
}

If the JSON is not well formatted, I would like to catch and handle the
exception that is thrown by Jackson. Is there a way to do this? I have
tried using @Provider to catch Exception or Throwable or even the
specific Jackson exceptions, but the provider is never called.

Is there a way to do this, or do I have to deserialize by hand with in
the resource method?

Thanks for your help