1)我可以按如下方式创建复杂的读取:
implicit val locationReads: Reads[Location] = (
(JsPath \ "lat").read[Double] and
(JsPath \ "long").read[Double]
)(Location.apply _)
'和'定义在哪里?我查找了play.libs.api.functional.syntax._但是在文档中找不到包裹?
2)在上面的代码中,(JsPath \“lat”)。read [Double]将返回另一个JsPath。如何'和'采用这个JsPath并将其与(JsPath \“long”)结合起来。阅读[Double] /
3)我可以按如下方式创建自定义验证:
val improvedNameReads =
(JsPath \ "name").read[String](minLength[String](2))
Reads.minLength在哪里定义?我在Reads.scala中寻找它,但在那里找不到它。
答案 0 :(得分:0)
它被称为
Applicative functor
以下是具体实现JSON格式的解释:
http://mandubian.com/2012/09/08/unveiling-play-2-dot-1-json-api-part1-jspath-reads-combinators/
https://gist.github.com/sadache/3646092#file-2-functionalbuilder-scala
您可以在互联网上找到更多内容,例如:
https://softwaremill.com/applicative-functor/
您的代码使用and
:
Products.scala