After upgrading to Slick 3.0 and Play! 2.4, I got this pretty dependency injection feature, but I faced with serialization problems. My Application is simple rest server.
This is the exception which I get
type mismatch;
found : play.api.libs.json.OWrites[ReportsDatabase.this.PostEntity]
required: play.api.libs.json.Writes[ApiRoot.this.noiseModel.PostEntity]
Note: implicit value PostWrites is not applicable here because it comes after the application point and it lacks an explicit result type
This is my entity
val posts = TableQuery[Posts]
case class PostEntity(id: Long, user: Long, text: String, date: LocalDate, lat: Double, lon: Double, pictureID: Long, soundId: Long)
class Posts(tag: Tag) extends Table[PostEntity](tag, "post") {
implicit val dateColumnType = MappedColumnType.base[LocalDate, String](dateFormatter.print(_), dateFormatter.parseLocalDate)
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def userId = column[Long]("userId")
def text = column[String]("text")
def date = column[LocalDate]("date_post")
def lat = column[Double]("lat")
def lon = column[Double]("lon")
def pictureId = column[Long]("pictureID")
def soundId = column[Long]("soundId")
def * = (id, userId, text, date, lat, lon, pictureId, soundId) <>(PostEntity.tupled, PostEntity.unapply)
def user = foreignKey("post_user_FK", userId, users)(_.id)
}
Here is method to get a list of posts
def getPostList: Future[Seq[PostEntity]] = db.run(posts.result)
My controller starts like this
class ApiRoot @Inject() (noiseDao: NoiseModel, noiseModel: ReportsDatabase) extends Controller {
import noiseModel._
implicit val PostWrites = Json.writes[noiseModel.PostEntity]
def getPostStream = Action.async { implicit request =>
noiseDao.getPostList.map{posts =>
Ok(toJson(posts))
}
}
def getPost(id: Long) = Action.async { implicit request =>
noiseDao.getPost(id).map{ post =>
Ok(toJson(post))
}
}
I haven't found any information in the Internet regarding this problem. Found questions, but any answers.