我试图通过使用
jackson-module-scala和他们的例子在播放应用程序中取消/编组json:
val mapper = new ObjectMapper()
mapper.registerModule(DefaultScalaModule)
我在Build.scala中包含了这些库
"com.fasterxml" % "jackson-module-scala" % "1.9.3",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.3.0",
和进口:
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
但是,当我运行Play App时,我收到以下错误:
[error] found : com.fasterxml.jackson.module.scala.DefaultScalaModule.type
[error] required: com.fasterxml.jackson.databind.Module
[error] mapper.registerModule(DefaultScalaModule)
play.PlayExceptions$CompilationException: Compilation error[type mismatch;
found : com.fasterxml.jackson.module.scala.DefaultScalaModule.type
required: com.fasterxml.jackson.databind.Module]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.3.jar:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:304) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:298) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.3.jar:na]
任何帮助将不胜感激.
最佳答案 终于能够搞清楚了.
我试图获得最新版本的jackson-module-scala;通过检查:http://mvnrepository.com/artifact/com.fasterxml/jackson-module-scala,最新版本似乎是1.9.3
然而,适当的地方看起来有适当的最新版本2.3.0:http://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-scala_2.10
通过将Build.scala更改为:
...
"com.fasterxml" % "jackson-module-scala_2.10" % "2.3.0",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.3.0",
...
甚至更好地使用“%%”(对于自动scala版本解析;不需要添加“_scala.ver”):
...
"com.fasterxml" %% "jackson-module-scala" % "2.3.0",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.3.0",
...