codahale/dropwizard — Issue #23: Scala resources returning objects don't work with 0.1.3
Author: syrnick
Created: 2012-01-25 00:19:07+00:00
State: open

Here's a resource

```scala

package com.scala.aboutdropwizard

import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Produces, Path}

case class DumbResult(val itIsOk: Boolean)

@Path("/hello-scala-world")
@Produces(Array(MediaType.APPLICATION_JSON))
class HelloScalaWorldResource {

@GET def wellHello(): DumbResult = {
DumbResult(true)
}
}
```

And a scala service:

```scala

package com.scala.aboutdropwizard

import scala.collection.mutable.ArrayBuilder

import com.aboutdropwizard._

import com.yammer.dropwizard.Service
import com.yammer.dropwizard.config.Environment

class HelloScalaWorldService extends Service[HelloWorldConfiguration]("The scala hello world") {

def initialize(config: HelloWorldConfiguration, environment: Environment) {

val template = config.getTemplate
val defaultName = config.getDefaultName

environment.addResource(new HelloWorldResource(template, defaultName));
environment.addResource(new HelloScalaWorldResource)
environment.addHealthCheck(new TemplateHealthCheck(template));
}
}

object HelloScalaWorldService {
def main(args: Array[String]) = new HelloScalaWorldService().run(args)
}
```

Doing curl -v http://127.0.0.1:8080/hello-scala-world

produces the following error:

```
ERROR [2012-01-25 00:11:33,141] com.sun.jersey.spi.container.ContainerResponse: A message body writer for Java class com.scala.aboutdropwizard.DumbResult, and Java type class com.scala.aboutdropwizard.DumbResult, and MIME media type application/json was not found
ERROR [2012-01-25 00:11:33,142] com.sun.jersey.spi.container.ContainerResponse: The registered message body writers compatible with the MIME media type are:

application/json ->
com.yammer.dropwizard.jersey.JacksonMessageBodyProvider
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
```

The java version of the resource works fine.

Using @Produces(MediaType.APPLICATION_JSON) in scala instead of @Produces(Array(MediaType.APPLICATION_JSON)) produces compile-time error

```
[ERROR] found : java.lang.String("application/json")
[ERROR] required: Array[java.lang.String]
[ERROR] @Produces(MediaType.APPLICATION_JSON)
```

I'm at a loss w.r.t. what's going on. Any suggestions?