scala - Can't unmarshall json HttpEntity with spray-json -
i trying run simple example documentation without changes:
import spray.json.defaultjsonprotocol import spray.httpx.unmarshalling._ import spray.httpx.marshalling._ import spray.http._ import httpcharsets._ import mediatypes._ case class person(name: string, firstname: string, age: int) object myjsonprotocol extends defaultjsonprotocol { implicit val personformat = jsonformat3(person) } import myjsonprotocol._ import spray.httpx.sprayjsonsupport._ import spray.util._ val bob = person("bob", "parr", 32) val body = httpentity( contenttype = contenttype(`application/json`, `utf-8`), string = """|{ | "name": "bob", | "firstname": "parr", | "age": 32 |}""".stripmarginwithnewline("\n") ) marshal(bob) body.as[person] and fails on last line ("body.as[person]") following error , stacktrace:
exception in thread "main" java.lang.nosuchmethoderror: spray.json.jsonparser$.apply(ljava/lang/string;)lspray/json/jsvalue; @ spray.httpx.sprayjsonsupport$$anonfun$sprayjsonunmarshaller$1.applyorelse(sprayjsonsupport.scala:36) @ spray.httpx.sprayjsonsupport$$anonfun$sprayjsonunmarshaller$1.applyorelse(sprayjsonsupport.scala:34) @ scala.runtime.abstractpartialfunction.apply(abstractpartialfunction.scala:36) @ spray.httpx.unmarshalling.unmarshaller$$anon$1$$anonfun$unmarshal$1.apply(unmarshaller.scala:29) @ spray.httpx.unmarshalling.simpleunmarshaller.protect(simpleunmarshaller.scala:40) @ spray.httpx.unmarshalling.unmarshaller$$anon$1.unmarshal(unmarshaller.scala:29) @ spray.httpx.unmarshalling.simpleunmarshaller.apply(simpleunmarshaller.scala:29) @ spray.httpx.unmarshalling.simpleunmarshaller.apply(simpleunmarshaller.scala:23) @ spray.httpx.unmarshalling.package$pimpedhttpentity.as(package.scala:39) @ com.example.m1$.delayedendpoint$com$example$m1$1(m1.scala:34) @ com.example.m1$delayedinit$body.apply(m1.scala:3) @ scala.function0$class.apply$mcv$sp(function0.scala:34) @ scala.runtime.abstractfunction0.apply$mcv$sp(abstractfunction0.scala:12) @ scala.app$$anonfun$main$1.apply(app.scala:76) @ scala.app$$anonfun$main$1.apply(app.scala:76) @ scala.collection.immutable.list.foreach(list.scala:381) @ scala.collection.generic.traversableforwarder$class.foreach(traversableforwarder.scala:35) @ scala.app$class.main(app.scala:76) @ com.example.m1$.main(m1.scala:3) @ com.example.m1.main(m1.scala) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140) what can wrong code? dependencies following (build.sbt):
scalaversion := "2.11.7" librarydependencies ++= seq( "io.spray" %% "spray-can" % "1.3.1", "io.spray" %% "spray-routing" % "1.3.1", "io.spray" %% "spray-json" % "1.3.2", "com.typesafe.akka" %% "akka-actor" % "2.3.11" ) i found bug related incompatibility between spray-httpx , spray-json seems has been resolved. using recent stable versions of libraries.
what else can wrong?
looks version incompatibility issue between spray-http , spray-json, these specific versions work without problems:
librarydependencies ++= seq( "io.spray" %% "spray-can" % "1.3.3", "io.spray" %% "spray-routing" % "1.3.3", "io.spray" %% "spray-json" % "1.3.2", "com.typesafe.akka" %% "akka-actor" % "2.3.11" )
Comments
Post a Comment