Add support for Java8 date/time @QueryParams
The bundle seems to suppose using date/times as path parameters, but you are missing an implementation for query parameters.
@cowwoc Would moving to Dropwizard 1.0.0-rc2 (which supports the Java Date/Time API in JAX-RS parameters) be an option for you?
@joschi I just tried upgrading and ran into a lot of problems (conflicting transitive dependencies, classloader issues, etc). I don't think the Dropwizard dependencies are fully caught up yet.
Here is an implementation that we wrote that worked for us:
@Provider
@Singleton
public class LocalDateTimeConverter implements ParamConverterProvider {
@Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (!rawType.isAssignableFrom(LocalDateTime.class)) {
return null;
}
return new ParamConverter<T>() {
@Override
@SuppressWarnings("unchecked")
public T fromString(final String value) {
if (value == null) {
throw new IllegalArgumentException("value may not be null");
}
return (T) LocalDateTime.parse(value);
}
@Override
public String toString(final T value) {
return ((LocalDateTime) value).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}
};
}
}
UPDATED on November 16th 2016. Original implementation of fromString() did not handle null values correctly.
I just tried upgrading and ran into a lot of problems (conflicting transitive dependencies, classloader issues, etc).
Did you post this to the Dropwizard mailing list or open an issue on GitHub?
I don't think the Dropwizard dependencies are fully caught up yet.
Could you please elaborate on this?