0

I've created a class to override JsonMappingException. Here is my custom exception handler.

@Provider
public class JsonMappingExceptionMapper implements ExceptionMapper<JsonMappingException> {

public JsonMappingExceptionMapper(){
    System.out.println("I am called");
} 

@Override
public Response toResponse( JsonMappingException e ) {

System.out.println("Should be called");
return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN)
                .entity("The supplied JSON contained an invalid property: " + "").build();
}
} 

But this is not being invoked and instead I am getting HTTP 500 error.

Caused by: org.codehaus.jackson.map.JsonMappingException: Can not construct instance of boolean from String value '': only "true" or "false" recognized
at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@463a4396; line: 5, column: 20]
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:160)

I have also packaged the compiled custom ExceptionMapper class with my web application project.

public class MyApplication extends Application{
@Override
public Set<Object> getSingletons()
{
    Set<Object> singleton = new HashSet<Object>();
    singleton.add(new JsonMappingExceptionMapper());
    return singleton;
}
akashag26
  • 123
  • 1
  • 1
  • 7

0 Answers0