0
votes

I'm using IntelliJ 14.1.4 and Play framework 2.4. I copied some code from this github project: https://github.com/JAVEO/play-reactivemongo-polymer to test out reactivemongo. Basically, I copied the Posts.scala to my controller folder. It's a class:

package controllers

import javax.inject.Inject

import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json.Json
import play.api.mvc.{Action, BodyParsers, Call, Controller, Result}
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}
import reactivemongo.api.commands.WriteResult
import reactivemongo.bson.{BSONDocument, BSONObjectID}
import reactivemongo.core.actors.Exceptions.PrimaryUnavailableException

class Posts @Inject()(val reactiveMongoApi: ReactiveMongoApi)
  extends Controller with MongoController with ReactiveMongoComponents {
...
}

in the routes file, IntellJ cannot resolve this line:

GET     /api/posts                  controllers.Posts.list

It seems that IntellJ only recognize controllers declared as object but not class.

Trying to run this using activator got the compilation error:

No Json serializer as JsObject found for type play.api.libs.json.JsObject. Try to implement an implicit OWrites or OFormat for this type
...

Any help?

1
As the original sample app is working fine, it's necessary to check your dependencies and that you properly use import play.modules.reactivemongo.json._: reactivemongo.org/releases/0.11/documentation/…cchantep
I think there are two problems here. First problem is about IntelliJ cannot resolve injected routes. The second problem is Json serializer. I tried to import the github example. IntelliJ also cannot resolve controllers.Posts.list.yang
For the second problem, it turns out to be related to play reactivemongo versions. In my build.sbt, I used "0.11.6.play24" as the tutorial on reactivemongo suggested. This causes the error message of "No Json ...". I changed the version to "0.11.0.play24" as the github example did. The error message went away.yang
As indicated check the imports correspond to the used version.cchantep
I tried to add import play.modules.reactivemongo.json._ and use 0.11.6.play24. It didn't solve the problem. Still throws the No Json error.yang

1 Answers

0
votes

Upgrade plugin and intellij to the latest version solved the problem. Looks like a bug.