Skip to content
This repository has been archived by the owner on Mar 3, 2019. It is now read-only.

Add support for Java8 date/time @QueryParams #26

Open
cowwoc opened this issue May 3, 2016 · 4 comments
Open

Add support for Java8 date/time @QueryParams #26

cowwoc opened this issue May 3, 2016 · 4 comments

Comments

@cowwoc
Copy link

cowwoc commented May 3, 2016

The bundle seems to suppose using date/times as path parameters, but you are missing an implementation for query parameters.

@joschi
Copy link
Member

joschi commented May 4, 2016

@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?

@cowwoc
Copy link
Author

cowwoc commented May 5, 2016

@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.

@cowwoc
Copy link
Author

cowwoc commented May 5, 2016

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.

@joschi
Copy link
Member

joschi commented May 9, 2016

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants