Scala在构造上播放读取Json和LocalDateTime

Scala在构造上播放读取Json和LocalDateTime,json,scala,playframework,Json,Scala,Playframework,我有一个简单的case类位置(基本上是ScalaJsonCombinators教程) 我想设置施工的当前时间,以便我的位置如下所示: case class Location(latitude: Double, longitude: Double, date: LocalDateTime) 不幸的是,我无法真正理解如何使用Play Json来传递LocalDateTime.now(),而不发送额外的字段,或者实际上如何传递LocalDateTime 请求机构 { "latitude"

我有一个简单的case类位置(基本上是ScalaJsonCombinators教程)

我想设置施工的当前时间,以便我的位置如下所示:

case class Location(latitude: Double, longitude: Double, date: LocalDateTime)
不幸的是,我无法真正理解如何使用Play Json来传递LocalDateTime.now(),而不发送额外的字段,或者实际上如何传递LocalDateTime

请求机构

{ 
     "latitude": ...
     "longitude": ...
}

而不是传递
位置。取消应用
/
位置。将
应用到
FunctionalBuilder
您可以传递自己的函数:

case class Location(latitude: Double, longitude: Double, date: LocalDateTime)

implicit val locationWrites: Writes[Location] =
(
  (JsPath \ "latitude").write[Double] and
  (JsPath \ "longitude").write[Double]
) ((l: Location) => (l.latitude, l.longitude))

implicit val locationReads: Reads[Location] =
(
  (JsPath \ "latitude").read[Double] and
  (JsPath \ "longitude").read[Double]
) ((lat: Double, lon: Double) => Location(lat, lon, LocalDateTime.now()))

而不是传递
位置。取消应用
/
位置。将
应用到
FunctionalBuilder
您可以传递自己的函数:

case class Location(latitude: Double, longitude: Double, date: LocalDateTime)

implicit val locationWrites: Writes[Location] =
(
  (JsPath \ "latitude").write[Double] and
  (JsPath \ "longitude").write[Double]
) ((l: Location) => (l.latitude, l.longitude))

implicit val locationReads: Reads[Location] =
(
  (JsPath \ "latitude").read[Double] and
  (JsPath \ "longitude").read[Double]
) ((lat: Double, lon: Double) => Location(lat, lon, LocalDateTime.now()))