Json变形金刚:缺少隐含的减少

时间:2013-09-06 03:13:35

标签: json scala playframework-2.0

http://www.playframework.com/documentation/2.1.2/ScalaJsonTransformers跟随Play的文档:

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

val gizmo2gremlin = (
    (__ \ 'name).json.put(JsString("gremlin")) and
    (__ \ 'description).json.pickBranch(
            (__ \ 'size).json.update( of[JsNumber].map{ case JsNumber(size) => JsNumber(size * 3) } ) and
            (__ \ 'features).json.put( Json.arr("skinny", "ugly", "evil") ) and
            (__ \ 'danger).json.put(JsString("always")) 
            reduce
    ) and
    (__ \ 'hates).json.copyFrom( (__ \ 'loves).json.pick )
) reduce

我认为上面的of[JsNumber]实际上应该是Format.of[JsNumber],但即使在那之后,代码也无法编译:

could not find implicit value for parameter reducer: play.api.libs.functional.Reducer[play.api.libs.json.JsObject,B]
               reduce
               ^

我是否错过了导入,或者文档中是否有错误?

1 个答案:

答案 0 :(得分:1)

原来缺少的导入是:

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