如何在Play + Scala中为自定义对象定义json编写器? [英] How do I define json writer for custom object in Play + Scala?
问题描述
您能否演示一下如何在Scala和Play Framework 2.1-RC2中为我的课程定义json writer?
Could you please demostrate how I can define json writer for my class in Scala and Play Framework 2.1-RC2 ?
文档非常混乱(并且将成为Web开发人员社区广泛采用Scala/Play的重大障碍).例如,不仅不清楚确切的以下代码在哪里(摘自 此处 )应该位于
The documentation is quite confusing (and will be significant obstacle for wider adoption of Scala/Play by web-developer community). For example not only it's unclear where exactly following code (taken from here) should be located
implicit val taskWrites = (
(__ \ "id").write[String] ~
(__ \ "label").write[Boolean] ~
)(unlift(Task.unapply))
,但是如果我将其放在object
定义中,它也是不可编译的.播放给我以下错误
but it's also not compilable if I put it inside object
definition. Play gives me following error
not found: value __
这是我的Task.scala
Here is my Task.scala
推荐答案
嗯,事实证明问题很明显.我忘了导入play.api.libs.functional.syntax._
.
Well, turned out the problem was obvious. I forgot to import play.api.libs.functional.syntax._
.
这篇关于如何在Play + Scala中为自定义对象定义json编写器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!