package io.dropwizard.jersey.jackson;

import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

/**
 * A Jersey provider which enables using Jackson to parse request entities into objects and generate
 * response entities from objects.
 * <p/>
 * (Essentially, extends {@link JacksonJaxbJsonProvider} with support for {@link JsonIgnoreType}.)
 */
public class JacksonMessageBodyProvider extends JacksonJaxbJsonProvider {
    private final ObjectMapper mapper;

    public JacksonMessageBodyProvider(ObjectMapper mapper) {
        this.mapper = mapper;
        setMapper(mapper);
    }

    @Override
    public boolean isReadable(Class<?> type,
                              Type genericType,
                              Annotation[] annotations,
                              MediaType mediaType) {
        return isProvidable(type) && super.isReadable(type, genericType, annotations, mediaType);
    }

    @Override
    public boolean isWriteable(Class<?> type,
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType) {
        return isProvidable(type) && super.isWriteable(type, genericType, annotations, mediaType);
    }

    @Override
    public Object readFrom(Class<Object> type,
                           Type genericType,
                           Annotation[] annotations,
                           MediaType mediaType,
                           MultivaluedMap<String, String> httpHeaders,
                           InputStream entityStream) throws IOException {
        try {
            return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
        } catch (IOException e) {
            if (e instanceof JsonProcessingException) {
                throw e;
            }

            // Deserializing malformatted URLs, for instance, will result in an IOException so
            // wrap in an exception we can handle
            throw JsonMappingException.fromUnexpectedIOE(e);
        }
    }

    private boolean isProvidable(Class<?> type) {
        final JsonIgnoreType ignore = type.getAnnotation(JsonIgnoreType.class);
        return (ignore == null) || !ignore.value();
    }

    public ObjectMapper getObjectMapper() {
        return mapper;
    }
}

@@ -92,127 +92,8 @@
 pe;%0A
-import com.fasterxml.jackson.core.JsonProcessingException;%0Aimport com.fasterxml.jackson.databind.JsonMappingException;%0A
 impo
@@ -245,104 +245,8 @@
 pe;%0A
-import javax.ws.rs.core.MultivaluedMap;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A
 impo
@@ -1454,832 +1454,8 @@
  %7D%0A%0A
-    @Override%0A    public Object readFrom(Class%3CObject%3E type,%0A                           Type genericType,%0A                           Annotation%5B%5D annotations,%0A                           MediaType mediaType,%0A                           MultivaluedMap%3CString, String%3E httpHeaders,%0A                           InputStream entityStream) throws IOException %7B%0A        try %7B%0A            return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);%0A        %7D catch (IOException e) %7B%0A            if (e instanceof JsonProcessingException) %7B%0A                throw e;%0A            %7D%0A%0A            // Deserializing malformatted URLs, for instance, will result in an IOException so%0A            // wrap in an exception we can handle%0A            throw JsonMappingException.fromUnexpectedIOE(e);%0A        %7D%0A    %7D%0A%0A
     

Remove dead code in the jackson provider