package com.yammer.dropwizard.jersey;

import org.codehaus.jackson.JsonProcessingException;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

public class JsonProcessingExceptionMapper implements ExceptionMapper<JsonProcessingException> {
    @Override
    public Response toResponse(JsonProcessingException exception) {
        throw new WebApplicationException(exception, Response.Status.BAD_REQUEST);
    }
}

@@ -43,97 +43,307 @@
 ort 
-org.codehaus.jackson.JsonProcessingException;%0A%0Aimport javax.ws.rs.WebApplicationException
+com.google.common.base.Splitter;%0Aimport com.yammer.dropwizard.jetty.UnbrandedErrorHandler;%0Aimport com.yammer.dropwizard.logging.Log;%0Aimport org.codehaus.jackson.JsonProcessingException;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.ws.rs.core.Context;%0Aimport javax.ws.rs.core.MediaType
 ;%0Aim
@@ -413,16 +413,73 @@
 nMapper;
+%0Aimport java.io.IOException;%0Aimport java.io.StringWriter;
 %0A%0Apublic
@@ -577,167 +577,2017 @@
     
-@Override%0A    public Response toResponse(JsonProcessingException exception) %7B%0A        throw new WebApplicationException(exception, Response.Status.BAD_REQUEST)
+private static final Log LOG = Log.forClass(JsonProcessingExceptionMapper.class);%0A    private static final Splitter LINE_SPLITTER = Splitter.on(%22%5Cn%22).trimResults();%0A%0A    @Context%0A    private HttpServletRequest request;%0A%0A    private final UnbrandedErrorHandler errorHandler;%0A%0A    public JsonProcessingExceptionMapper() %7B%0A        this.errorHandler = new UnbrandedErrorHandler();%0A    %7D%0A%0A    @Override%0A    public Response toResponse(JsonProcessingException exception) %7B%0A        final String message = exception.getMessage();%0A%0A        /*%0A         * This is a super-specific edge case. Lots of folks forget to add a no-arg constructor, or%0A         * depend on a type which isn't deserializable and they won't find out until here. It's not%0A         * a 400, for sure, since nothing the client can change will help.%0A         */%0A        if (message.startsWith(%22No suitable constructor found%22)) %7B%0A            LOG.error(exception, %22Unable to deserialize the specific type%22);%0A            return Response.serverError().build();%0A        %7D%0A%0A        try %7B%0A            LOG.debug(exception, %22Unable to process JSON%22);%0A            final StringWriter writer = new StringWriter(4096);%0A%0A            errorHandler.writeErrorPage(request,%0A                                        writer,%0A                                        400,%0A                                        stripLocation(message),%0A                                        false);%0A            return Response.status(Response.Status.BAD_REQUEST)%0A                           .type(MediaType.TEXT_HTML_TYPE)%0A                           .entity(writer.toString())%0A                           .build();%0A        %7D catch (IOException e) %7B%0A            LOG.debug(e, %22Unable to output error message%22);%0A            return Response.serverError().build();%0A        %7D%0A    %7D%0A%0A    @SuppressWarnings(%22LoopStatementThatDoesntLoop%22)%0A    private String stripLocation(String message) %7B%0A        for (String s : LINE_SPLITTER.split(message)) %7B%0A            return s;%0A        %7D%0A        return message
 ;%0A  

Fix JsonProcessingExceptionMapper.