0

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?

yang
  • 498
  • 5
  • 22
  • 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._`: http://reactivemongo.org/releases/0.11/documentation/release-details.html – cchantep Aug 20 '15 at 11:16
  • 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 Aug 21 '15 at 02:41
  • 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 Aug 21 '15 at 03:51
  • As indicated check the imports correspond to the used version. – cchantep Aug 21 '15 at 07:28
  • 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 Aug 22 '15 at 07:05
  • Please check your code, that you use the right dependency, the recommanded imports, and not others. The sample app is working fine with 0.11.6.play24: https://github.com/cchantep/play-reactivemongo-polymer/tree/0.11.6.play24?files=1 – cchantep Aug 22 '15 at 09:50

1 Answers1

0

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

yang
  • 498
  • 5
  • 22