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
               ^

我错过了导入,还是文档中有错误?

4

1 回答 1

1

原来缺少的导入是:

import play.api.libs.json.Reads._
于 2013-09-10T02:06:09.060 回答