I am trying to split format to multiple tuples so it can handle more than 22 fields in the case class. However, I got an error "value and is not a member of play.api.libs.json.Format". How can I merge multiple formats for a case class?
val fields1to2: Format[(Int, String)] = (
(__ \ "a").format[Int] and
(__ \ "b").format[String]
).tupled
val fields3to4: Format[(Boolean, List[Int])] = (
(__ \ "c").format[Boolean] and
(__ \ "d").format[List[Int]]
).tupled
implicit val hugeCaseClassReads: Format[Huge] = (
fields1to2 and fields3to4 // "value and is not a member of play.api.libs.json.Format"
) {
case ((a, b), (c, d)) =>
Huge(a, b, c, d)
}
If you are not limited to use only Play-JSON then try the Play-Json extensions library:
import ai.x.play.json.Jsonx
implicit val hugeCaseClassReads: Format[Huge] = Jsonx.formatCaseClass
But a more handy, safe, and efficient option would be using of jsoniter-scala - it has built in support of case classes with huge numbers of fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With