Play Scala文档显示了如何以两种方式序列化JSON,第一种:
implicit val locationWrites = new Writes[Location] {
def writes(location: Location) = Json.obj(
"lat" -> location.lat,
"long" -> location.long
)
}
然后使用组合器:
implicit val locationWrites: Writes[Location] = (
(JsPath \ "lat").write[Double] and
(JsPath \ "long").write[Double]
)(unlift(Location.unapply))
选择一种方法而不是另一种方法应该考虑哪些原因?