22フィールドの制限のため、大文字のクラスをより小さなクラスに分割する必要がありました。この大きなクラスのWrites
をどうすれば平滑化できますか?プレーでの書き込みの平滑化
import play.api.libs.json._
import play.api.libs.functional.syntax._
case class B(x: Option[Int], y: Option[Int])
object B {
implicit val format: (Reads[B], Writes[B]) => Format[B] = Format[B]
}
case class C(z: Option[Int], w: Option[Int])
object C {
implicit val format: (Reads[C], Writes[C]) => Format[C] = Format[C]
}
case class A(b: B, c: C)
object A {
implicit val reads: Reads[A] =
(Reads.of[B] and Reads.of[C]) (A.apply _)
implicit val writes: Writes[A] = ???
/*
val a = A(B(1, 2), C(3, 4)
Json.toJson(a) should be
{
"x": 1
"y": 2
"z": 3
"w": 4
}
*/
}
これに相当するのは何ですか? –