我正在使用安全的社會和reactivemongo庫和scala編寫一個play 2.3應用程序。 現在我試圖實現UserService [T]特質,但我得到updatePasswordInfo方法的編譯錯誤。 這是方法:編譯未來的[選項[BasicProfile]]方法中的錯誤
def updatePasswordInfo(user: LoginUser,info: PasswordInfo): scala.concurrent.Future[Option[BasicProfile]] = {
implicit val passwordInfoFormat = Json.format[PasswordInfo]
//the document query
val query = Json.obj("providerId" -> user.providerId,
"userId" -> user.userId
)
//search if the user exists
val futureUser: Future[Option[LoginUser]] = UserServiceLogin.find(query).one
futureUser map {
case Some(x) => val newPassword = Json.obj("passswordInfo" -> info)// the new password
UserServiceLogin.update(query, newPassword) //update the document
val newDocument: Future[Option[LoginUser]] = UserServiceLogin.find(query).one
newDocument map {
case Some(x) => x
case None => None
} //return the new LoginUser
case None => None
}
}
這是編譯器錯誤:
/Users/alberto/git/recommendation-system/app/security/UserService.scala:203: type mismatch;
[error] found : scala.concurrent.Future[Product with Serializable]
[error] required: Option[securesocial.core.BasicProfile]
[error] newDocument map {
有什麼不對?
LoginUser是BasicProfile類的子類型。 編譯器給我一個錯誤:他說沒有找到optionT – 2014-09-24 12:13:58
@albertoadami,那麼這是因爲你需要添加ScalaZ到你的依賴關係。無論如何,在這種情況下,你可以很容易做到,因爲你不需要對'user'對象做任何事情。 – 2014-09-24 13:17:26