0
我有一個簡單的案例類的位置(這是相當多的ScalaJsonCombinators教程)斯卡拉讀取播放JSON和LocalDateTime上構建
// controller
implicit val locationWrites: Writes[Location] =
(
(JsPath \ "latitude").write[Double] and
(JsPath \ "longitude").write[Double]
) (unlift(Location.unapply))
implicit val locationReads: Reads[Location] =
(
(JsPath \ "latitude").read[Double] and
(JsPath \ "longitude").read[Double]
) (Location.apply _)
// model
case class Location(latitude: Double, longitude: Double)
object Location {
implicit val formatter = Json.format[Location]
}
我想設置施工當前的時間,讓自己的位置看起來像:
case class Location(latitude: Double, longitude: Double, date: LocalDateTime)
可惜我不能真正弄清楚如何使用Play JSON來傳遞LocalDateTime.now(),而不發送附加字段或實際如何通過LocalDateTime一般。
請求主體
{
"latitude": ...
"longitude": ...
}
非常感謝!:) – Nextar