I decided to return to Dropwizard after a very long business with Spring. I quickly got the barebone REST absolute REST service service, and it works without a problem.
Using Dropwizard 0.7.1 and Java 1.8 , only POM entries are dropwizard kernel dependencies and the maven compiler plugin to force Java 1.8, as recommended by the Dropwizard user guide.
However, as soon as I try to add an optional QueryParam to the base controller, the application cannot start with the following error (short for brevity):
INFO [2015-01-03 17:44:58,059] io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources: GET / (edge.dw.sample.controllers.IndexController) ERROR [2015-01-03 17:44:58,158] com.sun.jersey.spi.inject.Errors: The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for method public java.lang.String edge.dw.sample.controllers.IndexController.index(java.util.Optional) at parameter at index 0 Exception in thread "main" javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-6c2ed0cd@3 30103b7==com.sun.jersey.spi.container.servlet.ServletContainer,1,false
The code for the controller is as follows:
@Path("/") public class IndexController { @GET @Timed public String index(@QueryParam("name") Optional<String> name) { String saying = "Hi"; if(name != null && name.isPresent()) { saying += " " + name.get(); } return saying; } }
If I remove the option from the mix, the application will work fine. I replace the optional code with null checks and it works fine.
Did I miss something fundamental here? Both Google Guava Optional and java.util.Optional crash with the same error. (And yes, I narrowed it down to an Option object)
A quick Google / SO search didnβt bring anything useful, but feel free to tell me a resource that I might have missed
Thanks in advance!
source share