您可以将平面 json 结构映射到分层对象结构。然后你不需要处理巨大的对象,你可以拥有超过 22 个字段。
case class SubObject(field4: String, field5:String)
case class MainObject(field1: String, field2: String, field3: String,
subObject: SubObject, field6: String, field7: String)
implicit val mainObjectFormat: Format[MainObject] = (
(__ \ "field1").format[String] and
(__ \ "field2").format[String] and
(__ \ "field3").format[String] and
(
(__ \ "field4").format[String] and
(__ \ "field5").format[String]
)(SubObject.apply, unlift(SubObject.unapply)) and
(__ \ "field6").format[String] and
(__ \ "field7").format[String]
(MainObject.apply, unlift(MainObject.unapply))