ReactiveMongo/Play-ReactiveMongo

Play2.4 JsObject.init method not found

RavisMsk opened this issue · 6 comments

Hello!

After updating to Play 2.4 i'm getting a strange error right at the start-up of application.
Stacktrace leads to ReactiveMongo sources and looks like this:

[ERROR] [05/22/2015 13:20:25.601] [RuCahAS-akka.actor.default-dispatcher-4] [akka.actor.ActorSystemImpl(RuCahAS)] Uncaught error from thread [RuCahAS-akka.actor.default-dispatcher-4] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
java.lang.NoSuchMethodError: play.api.libs.json.JsObject.<init>(Lscala/collection/Seq;)V
    at play.modules.reactivemongo.json.BSONFormats$BSONDocumentFormat$$anonfun$4.applyOrElse(json.scala:70)
    at play.modules.reactivemongo.json.BSONFormats$BSONDocumentFormat$$anonfun$4.applyOrElse(json.scala:69)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at play.modules.reactivemongo.json.BSONFormats$PartialFormat$class.writes(json.scala:34)
    at play.modules.reactivemongo.json.BSONFormats$BSONDocumentFormat.writes(json.scala:55)
    at play.modules.reactivemongo.json.BSONFormats$BSONDocumentFormat.writes(json.scala:55)
    at play.api.libs.json.Json$.toJson(Json.scala:118)
    at play.modules.reactivemongo.json.collection.JSONGenericHandlers$StructureBufferReader$.read(jsoncollection.scala:39)
    at play.modules.reactivemongo.json.collection.JSONGenericHandlers$StructureBufferReader$.read(jsoncollection.scala:37)
    at reactivemongo.api.collections.GenericHandlers$GenericBufferReader.read(genericcollection.scala:66)
    at reactivemongo.core.protocol.ReplyDocumentIterator.next(protocol.scala:308)
    at scala.collection.Iterator$class.foreach(Iterator.scala:750)
    at reactivemongo.core.protocol.ReplyDocumentIterator.foreach(protocol.scala:304)
    at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:59)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:183)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)
    at reactivemongo.api.DefaultCursor$$anonfun$collect$2.apply(cursor.scala:290)
    at reactivemongo.api.DefaultCursor$$anonfun$collect$2.apply(cursor.scala:276)
    at play.api.libs.iteratee.Iteratee$$anonfun$fold$1$$anonfun$apply$1.apply(Iteratee.scala:41)
    at play.api.libs.iteratee.internal$.eagerFuture(package.scala:30)
    at play.api.libs.iteratee.Iteratee$$anonfun$fold$1.apply(Iteratee.scala:41)
    at play.api.libs.iteratee.Iteratee$$anonfun$fold$1.apply(Iteratee.scala:41)
    at play.api.libs.iteratee.Iteratee$$anonfun$1.apply(Iteratee.scala:60)
    at play.api.libs.iteratee.Iteratee$$anonfun$1.apply(Iteratee.scala:60)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:399)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

After that app shuts down.
Seems like the problem is connected with play.api.libs.json.JsObject changes. After looking for init methods differences in 2.3 (https://www.playframework.com/documentation/2.3.x/api/scala/index.html#play.api.libs.json.JsObject) and 2.4 (https://www.playframework.com/documentation/2.4.x/api/scala/index.html#play.api.libs.json.JsObject) versions of play, i found that constructor has changed.
Old: new JsObject(fields: Seq[(String, JsValue)])
New: new JsObject(underlying: Map[String, JsValue])

Could ReactiveMongo underneath try to init JsObject with Seq?

Thanks in advance!

If that's the problem, there is a solution by just using companion-objects apply:
def apply(fields: Seq[(String, JsValue)]): JsObject
Or to use Json object:
def obj(fields: (String, JsValueWrapper)*): JsObject

This pull request should fix it: #129

@RadoBuransky Look here #126, I've already fixed everything for Play24 and sent pull request :)

There is a snapshot for play 2.4 available, see #125

It's better to look at #131 for details : the snapshot "org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play24-SNAPSHOT" is available on the OSS sonatype snapshots repo.