应该在Play 2.1 JSON解析控制器上启用编译器[warn] postfix运算符tupled

时间:2013-05-24 23:19:21

标签: scala playframework-2.1

我已根据Play Framework doc网站http://www.playframework.com/documentation/2.1.1/ScalaJsonRequests上的一个示例实现了我的第一个Play 2.1控制器。我的代码的操作部分看起来像:

object Sessions extends Controller {
  val log = LoggerFactory.getLogger(getClass())

  implicit val rds = (
    (__ \ 'userName).read[String] and
    (__ \ 'credentials).read[String]) tupled

  def session = Action(parse.json) { request =>
    log.trace("session request: {}", request)
    request.body.validate[(String, String)].map {
      case (userName, credentials) =>
        if (isAuthenticated(userName, credentials)) {
          Created(createSession(userName))
        } else {
          log.warn("userName: {} failed isAuthenticated", userName)
          BadRequest
        }
    }.recoverTotal {
      e =>
        val message = "Parse error: " + JsError.toFlatJson(e)
        log.warn(message)
        BadRequest
    }
  }

问题是Scala编译器警告“tupled”事情(是关键字,运算符,我不知道......我是新手)。我不知道警告是否真实,我应该采取建议的行动。警告的文字是

[warn] /Users/bobk/work/dm2-server/app/controllers/admin/Sessions.scala:20: postfix operator tupled should be enabled
[warn] by making the implicit value language.postfixOps visible.
[warn] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[warn] or by setting the compiler option -language:postfixOps.
[warn] See the Scala docs for value scala.language.postfixOps for a discussion
[warn] why the feature should be explicitly enabled.
[warn]     (__ \ 'credentials).read[String]) tupled
[warn]                                       ^
[warn] one warning found

搜索ScalaDocs有关“scala.language.postfixOps”的讨论没有任何结果;我找不到讨论。这个警告意味着什么?我应该采取建议措施让它消失吗?

我对Scala和Play有很多了解。

1 个答案:

答案 0 :(得分:2)

当您使用更多高级功能时,会显示这些类型的警告。 SIP 18: Modularizing Language Features更详细地解释了它。

在你的情况下,你可以这样做:

(__ \ 'credentials).read[String]).tupled

我建议您确保代码中没有任何警告。您想要解决这些类型的警告的方式取决于您。我通常导入该功能。