如何在Play + Scala中为自定义对象定义json编写器?

编程入门 行业动态 更新时间:2024-10-25 02:28:25
本文介绍了如何在Play + Scala中为自定义对象定义json编写器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您能否演示一下如何在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

pastebin/hG8F6Gqk

推荐答案

嗯,事实证明问题很明显.我忘了导入play.api.libs.functional.syntax._.

Well, turned out the problem was obvious. I forgot to import play.api.libs.functional.syntax._.

更多推荐

如何在Play + Scala中为自定义对象定义json编写器?

本文发布于:2023-07-14 22:09:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   中为   定义   对象   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!