question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java 8 LocalDate QueryParam

See original GitHub issue

It seems that parsing of Java 8 LocalDate as QueryParam is not liked. I get the following error on startup when trying with a simple controller.

    @GET
    public Integer testRatas(@QueryParam("foo") final LocalDate foo) {
        return 1;
    }
Caused by: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialisation.
[[FATAL] No injection source found for a parameter of type public java.lang.Integer resources.ForexRatesResource.testRatas(java.time.LocalDate) at index 0.; source='ResourceMethod{httpMethod=GET, consumedTypes=[], producedTypes=
[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class 
resources.ForexRatesResource, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@517a2b0]}, definitionMethod=public 
java.lang.Integer resources.ForexRatesResource.testRatas(java.time.LocalDate), parameters=
[Parameter [type=class java.time.LocalDate, source=foo, defaultValue=null]], responseType=cla
ss java.lang.Integer}, nameBindings=[]}']
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:555)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
    at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
    at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:640)
    ... 46 more

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
joschicommented, Oct 25, 2016

@OverlyExcessive Try using LocalDateParam:

    @GET
    @Path("/date")
    @Produces(MediaType.TEXT_PLAIN)
    public String receiveDate(@QueryParam("date") Optional<LocalDateParam> dateTimeParam) {
        if (dateTimeParam.isPresent()) {
            final LocalDateParam actualDateTimeParam = dateTimeParam.get();
            LOGGER.info("Received a date: {}", actualDateTimeParam);
            return actualDateTimeParam.get().toString();
        } else {
            LOGGER.warn("No received date");
            return null;
        }
    }
0reactions
chrisco484commented, Sep 20, 2021

It seems like you can provide a Parameter Converter implementation to allow direct support of LocalDate as described here:

Converting JAX-RS parameters

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Date Parameters in Spring - Baeldung
In this short tutorial, we'll learn how to accept Date, LocalDate, and LocalDateTime parameters in Spring REST requests, both at the request and ......
Read more >
JAX-RS and java.time.LocalDate as input parameter
Problem using JAX-RS and java. time. LocalDate (java8). How can I create some kind of an interceptor that maps json-dates to java.
Read more >
Converting JAX-RS parameters with ParamConverters
If you want JAX-RS to automatically convert parameters such as query params, path params, or others, you need to create a ParamConverter ....
Read more >
Spring Boot and the LocalDate request parameter - Medium
In my case that something is — a REST API with a LocalDate Request Parameter. ... Failed to convert value of type 'java.lang....
Read more >
Parsing of LocalDate query parameters in Spring Boot
RequestParam java.time.LocalDate] for value '2017-07-12'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found