JSON使用Play框架(Scala)中的硬编码值读取

bjf*_*her 4 json scala playframework

我想在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 _)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何做到这一点?

Mic*_*jac 5

使用Reads.pure生产Reads成品率恒定值.

implicit val locationReads: Reads[Location] = (
  Reads.pure("I am a hardcoded value") and
  (JsPath \ "lat").read[Double] and
  (JsPath \ "long").read[Double]
)(Location.apply _)
Run Code Online (Sandbox Code Playgroud)