Hi
I am trying to figure out how to return response in JSON format in the case
of exceptions. I have mapped the exception using ExceptionMapper, but the
overridden toResponse method only returns Response object.
Here is my code. Any help/ideas would be greatly appreciated.
Thanks
<code>
@Path("/test")
public class TestResource {
@GET
@Path("/userinfo")
@Produces(MediaType.APPLICATION_JSON)
public String getUserInfo(@QueryParam("userId") String userId) {
.....
throw new TestException("User not available");
}
}
@Provider
public class TestExceptionMapper implements ExceptionMapper<TestException> {
public Response toResponse(TestException ex) {
return
Response.status(404).entity(ex.getMessage()).type("application/json").build();
}
}
</code>
--
View this message in context: http://jersey.576304.n2.nabble.com/Returning-response-in-JSON-format-in-case-of-Exceptions-tp4985840p4985840.html
Sent from the Jersey mailing list archive at Nabble.com.