1

My Wildfly resteasy service is working fine, or was until I made a code change. No big deal, now I'm getting a deserialization error: "Problem deserializing 'setterless' property ..."

My question is whether there is anyway to get an error message in the client. I'm getting a Status of 400, and I can test that, but I'd like to get any message if possible. Any ideas?

If I get an error in the user code, I can set an error message in the header, but since there is a deserialization problem, the server is throwing a error before getting to any user code.

Paul Samsotha
  • 197,959
  • 33
  • 457
  • 689
K.Nicholas
  • 9,789
  • 4
  • 40
  • 57

1 Answers1

0

You can use an ExceptionMapper to handle the response returned to the client. JAX-RS has an exception hierarchy that will map to different responses and status codes. 400 in JAX-RS is a BadRequestException. So you could do something like

@Provider
public class BadRequestExceptionMapper
                      implements ExceptionMapper<BadRequestException> {
    @Override
    public Response toResponse(BadRequestException e) {
        Response response = Response.status(Response.Status.BAD_REQUEST)
                .entity("Sorry I forgot to implement a Setter").build();
        return response;
    }  
}

This isn't a very great example, because BadRequestException is thrown for many other reasons, than just forgetting a setter (or deserialization), but it demonstrates how you can intercept the response after the exception is thrown.

Community
  • 1
  • 1
Paul Samsotha
  • 197,959
  • 33
  • 457
  • 689