Scala enumeration serialization in jersey/jackson is not working for me -



Scala enumeration serialization in jersey/jackson is not working for me -

i've read jackson-module-scala page on enumeration handling (https://github.com/fasterxml/jackson-module-scala/wiki/enumerations). still i'm not getting work. essential code goes this:

@path("/v1/admin") @produces(array(mediatype.application_json + ";charset=utf-8")) @consumes(array(mediatype.application_json + ";charset=utf-8")) class restservice { @post @path("{type}/abort") def abortupload(@pathparam("type") typename: resourcetypeholder) { ... } } object resourcetype extends enumeration { type resourcetype = value val ssr, roadsegments, tmc, gab, tne = value } class resourcetypetype extends typereference[resourcetype.type] case class resourcetypeholder( @jsonscalaenumeration(classof[resourcetypetype]) resourcetype:resourcetype.resourcetype )

this how it's supposed work, right? still these errors:

following issues have been detected: warning: no injection source found parameter of type public void no.tull.restservice.abortupload(no.tull.resourcetypeholder) @ index 0. unavailable org.glassfish.jersey.server.model.modelvalidationexception: validation of application resource model has failed during application initialization. [[fatal] no injection source found parameter of type public void no.tull.restservice.abortupload(no.tull.resourcetypeholder) @ index 0.; source='resourcemethod{httpmethod=post, consumedtypes=[application/json; charset=utf-8], producedtypes=[application/json; charset=utf-8], suspended=false, suspendtimeout=0, suspendtimeoutunit=milliseconds, invocable=invocable{handler=classbasedmethodhandler{handlerclass=class no.tull.restservice, handlerconstructors=[org.glassfish.jersey.server.model.handlerconstructor@7ffe609f]}, definitionmethod=public void no.tull.restservice.abortupload(no.tull.resourcetypeholder), parameters=[parameter [type=class no.tull.resourcetypeholder, source=type, defaultvalue=null]], responsetype=void}, namebindings=[]}'] @ org.glassfish.jersey.server.applicationhandler.initialize(applicationhandler.java:467) @ org.glassfish.jersey.server.applicationhandler.access$500(applicationhandler.java:163) @ org.glassfish.jersey.server.applicationhandler$3.run(applicationhandler.java:323) @ org.glassfish.jersey.internal.errors$2.call(errors.java:289) @ org.glassfish.jersey.internal.errors$2.call(errors.java:286)

i have assembled tiny runnable project (while trying eliminate other complications) demonstrates problem: project.tgz

update: created sbt-file see if gradle building unusual build. got same result, build.sbt:

name := "project" version := "1.0" scalaversion := "2.10.4" val jacksonversion = "2.4.1" val jerseyversion = "2.13" librarydependencies ++= seq( "com.fasterxml.jackson.core" % "jackson-annotations" % jacksonversion, "com.fasterxml.jackson.core" % "jackson-databind" % jacksonversion, "com.fasterxml.jackson.jaxrs" % "jackson-jaxrs-json-provider" % jacksonversion, "com.fasterxml.jackson.jaxrs" % "jackson-jaxrs-base" % jacksonversion, "com.fasterxml.jackson.module" % "jackson-module-scala_2.10" % jacksonversion, "org.glassfish.jersey.containers" % "jersey-container-servlet-core" % jerseyversion ) seq(websettings :_*) librarydependencies ++= seq( "org.eclipse.jetty" % "jetty-webapp" % "9.1.0.v20131115" % "container", "org.eclipse.jetty" % "jetty-plus" % "9.1.0.v20131115" % "container" )

... , project/plugins.sbt:

addsbtplugin("com.earldouglas" % "xsbt-web-plugin" % "0.9.0")

you seem perchance have few problems tarball.

you need add together scala modules jackson able utilize scala functionality. can done doing this:

val jsonobjectmapper = new objectmapper() jsonobjectmapper.registermodule(defaultscalamodule) val jsonprovider: jacksonjsonprovider = new jacksonjsonprovider(jsonobjectmapper)

according working jersey-jackson example. need inject org.glassfish.jersey.jackson.jacksonfeature bailiwick of jersey found in jersey-media-json-jackson. restapplication.scala came out this

import javax.ws.rs.core.application import javax.ws.rs.ext.{contextresolver, provider} import com.fasterxml.jackson.databind.objectmapper import com.fasterxml.jackson.module.scala.defaultscalamodule import com.google.common.collect.immutableset import org.glassfish.jersey.jackson.jacksonfeature @provider class objectmapperprovider extends contextresolver[objectmapper] { val defaultobjectmapper = { val jsonobjectmapper = new objectmapper() jsonobjectmapper.registermodule(defaultscalamodule) jsonobjectmapper } override def getcontext(typ: class[_]): objectmapper = { defaultobjectmapper } } class restapplication extends application { override def getsingletons: java.util.set[anyref] = { immutableset.of( new restservice, new objectmapperprovider, new jacksonfeature ) } }

the real issue, though, @pathparam annotation. code path doesn't invoke jackson @ all. however, what's interesting bailiwick of jersey appears generically back upwards parsing type has constructor of single string. if modify resourcetypeholder can functionality want after all.

case class resourcetypeholder(@jsonscalaenumeration(classof[resourcetypetype]) resourcetype:resourcetype.resourcetype) { def this(name: string) = this(resourcetype.withname(name)) }

you might able add together generic back upwards enum holders bailiwick of jersey injectable provider. however, hasn't come in dropwizard-scala, project suffer same fate uses bailiwick of jersey too. imagine it's either impossible, or not mutual plenty have done work. when comes enum's, tend maintain mine in java.

scala jersey jackson enumeration

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -