org.codehaus.jackson.jaxrs.JsonParseExceptionMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-jaxrs Show documentation
Show all versions of jackson-jaxrs Show documentation
Jax-RS provider for JSON content type, based on
Jackson JSON processor's data binding functionality.
package org.codehaus.jackson.jaxrs;
import org.codehaus.jackson.JsonParseException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/**
* Implementation of {@link ExceptionMapper} to send down a "400 Bad Request"
* in the event unparsable JSON is received.
*/
@Provider
public class JsonParseExceptionMapper implements ExceptionMapper {
@Override
public Response toResponse(JsonParseException exception) {
return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).type("text/plain").build();
}
}