In my Play + Reactive Mongo application, I'm getting Future[Option[Student]] result and I' trying to match result:
def getStudent(id: String)=Action {
val futureOfStudent:Future[Option[Student]] = StudentRepository.getStudentById(id)
val timeoutFuture = play.api.libs.concurrent.Promise.timeout(0, Duration(3000, MILLISECONDS))
Async {
Future.firstCompletedOf(Seq(futureOfStudent, timeoutFuture)).map {
case s: Option[Student] => {s match {case Some(s)=>Ok(Json.toJson(s))
case None => NoContent}}
case i: Int => InternalServerError("Oooppppps!!!")
}
}
}
Everything works like charm but I'm getting ugly warning on case s: Option[Student] =>
- non-variable type argument model.Student in type pattern
Option[modelStudent] is unchecked since it is eliminated by erasure
How can I solve this warning?
I googled it and found some articles:
How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?
Why does Scala warn about type erasure in the first case but not the second?
but, it did not give me a clue how to solve as part of Play controller.
Please help.