Scala issues with fromJson
Closed this issue · 4 comments
the Scala sample pages is filled with errors
For example
import com.owlike.genson.defaultGenson_
is missing a . to be
import com.owlike.genson.defaultGenson._
This example
// {"name":"foo bar","age":28,"address":{"street":"rue des lapins",building:1337}}
val json = toJson(Person("foo bar", 28, Some(Address("rue des lapins", 1337)))
// {"name":"foo bar","age":28,"address":null}
val jsonWithNoAddress = toJson(Person("foo bar", 28, None)
val person = fromJson[Person](json)
Missing ) brackets to close on both val json = and val jsonWIthNoAddress line.
Even after fixing the errors attempting to run the example above with the 2 case classes. Just throws an error
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[RuntimeException: java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaMirrors$JavaMirror;]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaMirrors$JavaMirror;
at play.api.mvc.ActionBuilder$$anon$2.apply(Action.scala:463)
at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:112)
at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:112)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5.apply(Action.scala:111)
at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5.apply(Action.scala:110)
at scala.Option.map(Option.scala:146)
at play.api.mvc.Action$$anonfun$apply$2.apply(Action.scala:110)
at play.api.mvc.Action$$anonfun$apply$2.apply(Action.scala:103)
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:253)
Caused by: java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaMirrors$JavaMirror;
at com.owlike.genson.ScalaBeanPropertyFactory.<init>(ScalaBeanPropertyFactory.scala:18)
at com.owlike.genson.ScalaBundle.configure(ScalaBundle.scala:22)
at com.owlike.genson.GensonBuilder.withBundle(GensonBuilder.java:301)
at com.owlike.genson.package$.defaultGenson$lzycompute(package.scala:7)
at com.owlike.genson.package$.defaultGenson(package.scala:7)
at controllers.HomeController$$anonfun$index$1.apply(HomeController.scala:65)
at controllers.HomeController$$anonfun$index$1.apply(HomeController.scala:61)
at play.api.mvc.ActionBuilder$$anonfun$apply$13.apply(Action.scala:371)
at play.api.mvc.ActionBuilder$$anonfun$apply$13.apply(Action.scala:370)
at play.api.mvc.Action$.invokeBlock(Action.scala:498)
Thanks for reporting the typos.
What scala version are you using? What genson version are you using?
Looks like a version mismatch between the scala version you are using and the scala version for which genson has been built.
Scala "2.11.7" and latest Genson
Are you sure you are using the genson build for scala 2.11 and not scala 2.10?
http://mvnrepository.com/artifact/com.owlike/genson-scala_2.11/1.4,
if you are using sbt it would become libraryDependencies += "com.owlike" % "genson-scala_2.11" % "1.4"
or libraryDependencies += "com.owlike" %% "genson-scala" % "1.4"
to let sbt automatically pick the correct version.
My project is on 2.11.7 I am not sure what it was. due to time crunch I had to use json4s-jackson so I can't verify what it was. :( I'll close this issue.