Life's too short to use java.util.Collection
SJersey is a set of classes which add Scala interoperation to Jersey. It is intended to be a replacement for jersey-scala. Instead of Jerkson, jackson-module-scala (Jackson JSON) is used now.
##Versions:
- Build for both Scala 2.10 and 2.11.
- Bumped Jersey to 2.21
- Bumped jackson-module-scala to 2.5.1
- Added extractor support for
@HeaderParamand@FormParam - thanks to @kelnos for this
- Removed unneeded code from trait JacksonDeAndSerializer
- Fix: a WAR was deployed to Maven Central instead of the JAR
- bumped Jersey Version to 2.5.1
- bumped jackson-module-scala to 2.3.1
- bumped to Scala 2.10.3 and deployed to Central
- bumped versions for jersey-server and jackson-module-scala
First, specify Jersey-Scala as a dependency:
<dependency>
<groupId>eu.fakod</groupId>
<artifactId>sjersey_${scala.version.short}</artifactId>
<version>0.4.2</version>
</dependency>Currently valid values for ${scala.verion.short} are 2.10 and
2.11.
Second, configure the servlet (in case of using one):
<servlet>
<servlet-name>sjersey-service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>eu.fakod.sjersey.util.RegisterParameterInjectionBinder</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>my.resources.package;eu.fakod.sjersey.providers</param-value>
</init-param>
</servlet>
Third, write your resource classes:
case class FooCC(s: String, i: Int, d: Double, b: Boolean)
case class BarCC(s: String, i: Int)
@Path("/things")
@Consumes(Array("application/json"))
@Produces(Array("application/json"))
class Things {
@GET
def getAThing(@QueryParam("name") names: Set[String]) = "I found: " + names.mkString(", ")
@POST
def postAThing(cc: FooCC) = BarCC("received", cc.i)
}QueryParam-,HeaderParam-, andFormParam-annotated parameters of typeSeq[String],List[String],Vector[String],IndexedSeq[String],Set[String], andOption[String].JsonNoderequest and response entities.- Case class (i.e.,
Productinstances) JSON request and response entities. Array[A]request and response entities. (Due to the JVM's type erasure and mismatches between Scala and Java type signatures, this is the only "generic" class supported sinceArraytype parameters are reified.)