bretthoerner / dropwizard-scala

Scala helpers for Dropwizard.
86 stars 26 forks source link

Support dropwizard 0.8.0 #9

Closed lalloni closed 8 years ago

lalloni commented 9 years ago

Currently dropwizard-scala-0.7.1 does not work with the recently released dropwizard-0.8.0 version.

marc0der commented 9 years ago

In particular, it seems to be complaining about the type of the returned com.sun.jersey.api.core.ResourceConfig for JerseyEnvironment.getResourceConfig() when adding the ScalaBundle on initialisation. It now returns an org.glassfish.jersey.server.ResourceConfig.

java.lang.NoSuchMethodError: io.dropwizard.jersey.setup.JerseyEnvironment.getResourceConfig()Lcom/sun/jersey/api/core/ResourceConfig;
at com.massrelevance.dropwizard.bundles.ScalaBundle.run(ScalaBundle.scala:14)
at io.dropwizard.setup.Bootstrap.run(Bootstrap.java:180)
marc0der commented 9 years ago

I've dug a bit deeper, and it seems like this is going to be a bigger change that I had thought.

Dropwizard 0.8.0 depends on Jersey 2.16, where 0.7.x depended on Jersey 1.18. Jersey has been moved over to the org.glassfish namespace since 2.0, so much has changed in the API.

bretthoerner commented 9 years ago

Sorry folks, I'm open to patches (or handing the project off to someone more active) but I don't currently have any time to work on this. :(

I made an attempt at migrating to 0.8 many months ago but didn't get very far, there's quite a bit of change.

nbauernfeind commented 9 years ago

FWIW, I've successfully been using dropwizard 0.8 (for many months) with scala simply by registering jackson's scala module. You can do so like this:

import com.fasterxml.jackson.module.scala.DefaultScalaModule

object MyApp extends Application[MyConfiguration] {
  override def initialize(bootstrap: Bootstrap[MyConfiguration]): Unit = {
    bootstrap.getObjectMapper.registerModule(DefaultScalaModule)
    ...
  }

  override def run(cfg: MyConfiguration, env: Environment): Unit = {
    ...
  }
}

You lose out on the ability to use jersey injection of scala Longs/Ints/Booleans/Options/Collections. I never used any of those anyways (I prefer Guice for dependency injection, and json payloads for complex types). Maybe this is good enough for you too? In the worst case scala.collection.JavaConversions can be your friend =).

maximn commented 8 years ago

It's 0.9.2 now. Is this project maintained?

nbauernfeind commented 8 years ago

What I suggest in my previous comment is typically sufficient, except that the jackson-module-scala module still suffers from a bug or two that I haven't gotten a chance to track down yet.

bretthoerner commented 8 years ago

Sorry folks, I wasn't using Dropwizard (or Scala) for a long time there.

0.8.5 is released to Maven Central (thanks to others), 0.9.x doesn't work as-is so I'm looking into that.