播放包含超过22个字段的案例类的json合并格式

ang*_*okh 8 scala playframework playframework-2.3

我试图将格式拆分为多个元组,因此它可以处理案例类中超过22个字段.但是,我收到错误"值,并且不是play.api.libs.json.Format的成员".如何合并案例类的多种格式?

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)
}
Run Code Online (Sandbox Code Playgroud)

Ash*_*shp 0

添加这些导入解决了我的问题。在您的情况下,只需导入第一个就可以解决问题。

import play.api.libs.functional.syntax._

import play.api.libs.json.{Json, Reads, _}
Run Code Online (Sandbox Code Playgroud)