playframework组合器文档引发错误:找不到 - 为什么?

时间:2013-10-24 19:58:31

标签: playframework playframework-2.2

当我在组合器http://www.playframework.com/documentation/2.2.x/ScalaJsonCombinators的文档中尝试第一个例子时,它会在repl中引发错误,并且在播放应用程序中使用scala文件找不到值(尝试使用play 2.2.0并播放2.1。 1) - 从repl追溯:

Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import play.api.libs.json._
import play.api.libs.functional.syntax._

val customReads: Reads[(String, Float, List[String])] = 
  (JsPath \ "key1").read[String](email keepAnd minLength(5)) and 
  (JsPath \ "key2").read[Float](min(45)) and
  (JsPath \ "key3").read[List[String]] 
  tupled


// Exiting paste mode, now interpreting.

<console>:16: error: not found: value tupled
        tupled
        ^
<console>:11: error: not found: value email
        (JsPath \ "key1").read[String](email keepAnd minLength(5)) and 
                       ^

scala> 

那该怎么解决?

THX

1 个答案:

答案 0 :(得分:1)

两个问题。首先,您还需要一次导入:

import play.api.libs.json.Reads._

其次,在“minLength”和“min”之类的函数变得通用之前,可能会编写doc,以处理不仅仅是String和Float。所以你必须指定那些类型:

val customReads: Reads[(String, Float, List[String])] =
    (JsPath \ "key1").read[String](email keepAnd minLength[String](5)) and
    (JsPath \ "key2").read[Float](min[Float](45)) and
    (JsPath \ "key3").read[List[String]]
    tupled

这是我读过的讨论,我发现有关此方面的信息:

play-framework Google Group Discussion