我正在尝试将一个超级简单的JSON读取到Scala对象:
JSON:
{"base": 100, "sale": 75}
Scala的:
import play.api.libs.json._
import play.api.libs.functional.syntax._
case class Price(base: Int, sale: Option[Int])
object Price {
implicit val priceReads = (
(__ \ "base").read[Int] ~
(__ \ "sale").readNullable[Int]
)(Price)
}
这给了我以下来自Play的错误:
答案 0 :(得分:1)
试试这个:
import play.api.libs.json._
import play.api.libs.functional.syntax._
implicit val priceReads:Reads[Price] = (
(__ \ "base").read[Int] ~
(__ \ "sale").readNullable[Int]
)(Price.apply _)
奇怪的是,只是传递案例类不起作用......