package io.dropwizard.jersey.guava;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.jersey.internal.inject.Providers;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;

@Singleton
public class OptionalParamConverterProvider implements ParamConverterProvider {

    private final ServiceLocator locator;

    @Inject
    public OptionalParamConverterProvider(final ServiceLocator locator) {
        this.locator = locator;
    }

    @Override
    public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
        final List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(genericType);
        final ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null;
        if (ctp == null || ctp.rawClass() == String.class) {
            return new ParamConverter<T>() {
                @Override
                public T fromString(final String value) {
                    return rawType.cast(Optional.fromNullable(value));
                }

                @Override
                public String toString(final T value) throws IllegalArgumentException {
                    return value.toString();
                }
            };
        }
        final Set<ParamConverterProvider> converterProviders = Providers.getProviders(locator, ParamConverterProvider.class);
        for (ParamConverterProvider provider : converterProviders) {
            @SuppressWarnings("unchecked")
            final ParamConverter<?> converter = provider.getConverter(ctp.rawClass(), ctp.type(), annotations);
            if (converter != null) {
                return new ParamConverter<T>() {
                    @Override
                    public T fromString(final String value) {
                        return rawType.cast(Optional.fromNullable(value)
                                .transform(new Function<String, Object>() {
                                    @Override
                                    public Object apply(final String s) {
                                        return converter.fromString(value);
                                    }
                                }));
                    }

                    @Override
                    public String toString(final T value) throws IllegalArgumentException {
                        return value.toString();
                    }
                };
            }
        }
        return null;
    }
}
@@ -692,17 +692,16 @@
 vider %7B%0A
-%0A
     priv
@@ -1169,24 +1169,25 @@
 (0) : null;%0A
+%0A
         if (
@@ -1855,51 +1855,8 @@
 ) %7B%0A
-            @SuppressWarnings(%22unchecked%22)%0A
     

Remove superfluous @SuppressWarnings in OptionalParamConverterProvider