我想在JSON隐式读取中使用硬编码值,例如:
implicit val locationReads: Reads[Location] = (
"I am a hardcoded value" and // something like that
(JsPath \ "lat").read[Double] and
(JsPath \ "long").read[Double]
)(Location.apply _)
有谁知道怎么做?
答案 0 :(得分:3)
您可以使用自定义函数而不是Location.apply
:
case class Location(s: String, lat: Double, lon: Double)
object Location {
implicit val locationReads: Reads[Location] = (
(JsPath \ "lat").read[Double] and
(JsPath \ "long").read[Double]
)((lat, lon) => Location("I am a hardcoded value", lat, lon))
}