2013-10-24 41 views
1

當我嘗試組合器http://www.playframework.com/documentation/2.2.x/ScalaJsonCombinators的文檔中的第一個示例時,它會在播放應用程序中使用scala文件引發repl中找不到的值和錯誤(嘗試使用播放2.2.0和播放2.1.1) - 追溯from the repl:playframework combinators文檔引發錯誤:未找到 - 爲什麼?

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

兩個問題。首先,你需要一個更導入:

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

其次,文檔寫很可能喜歡「的minLength」和「分」的職能作了之前通用,處理的不僅僅是字符串越來越浮動。所以,你必須爲那些指定類型:

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

+0

感謝了很多解釋和指針「play-framework Google小組討論」 – pellekrogholt

相關問題