0

現在、scala 2.11.5 を使用しており、私のクラスの 1 つには 22 のフィールドがあります。

  case class CreateTransactionRequest(name: Option[String],
                                  balance: Option[BigDecimal],
                                  amount: BigDecimal,
                                  currency: String,
                                  dueDate: Option[DateTime],
                                  orderDate: DateTime,
                                  billing: Option[CreateAddressRequest],
                                  shipping: Option[CreateAddressRequest],
                                  status: String,
                                  email: String,
                                  paymentMethod: String,
                                  paymentTerm: Option[String],
                                  deliveryMethod: Option[String],
                                  source: String,
                                  attachments: Option[String],
                                  agent: Option[String],
                                  orders: Option[Set[CreateOrderRequest]],
                                  otherCharges: Option[Seq[CreateTransactionOtherChargeRequest]],
                                  notes: Option[Seq[CreateNoteRequest]],
                                  subscribers: Option[Seq[String]],
                                  trackingId: Option[String],
                                  acquisition: Option[String])

implicit val readsCreateTransactionRequest: Reads[CreateTransactionRequest] = Json.reads[CreateTransactionRequest]

周りを見回すと、解決策に出くわし、それを適用しました

val fields1to12: Reads[(Option[String], Option[BigDecimal], BigDecimal, String, Option[DateTime], DateTime, Option[CreateAddressRequest], Option[CreateAddressRequest], String, String, String, Option[String])] = (
    (__ \ "name").read[Option[String]] and
    (__ \ "balance").read[Option[BigDecimal]] and
    (__ \ "amount").read[BigDecimal] and
    (__ \ "currency").read[String] and
    (__ \ "dueDate").read[Option[DateTime]] and
    (__ \ "orderDate").read[DateTime] and
    (__ \ "billing").read[Option[CreateAddressRequest]] and
    (__ \ "shipping").read[Option[CreateAddressRequest]] and
    (__ \ "status").read[String] and
    (__ \ "email").read[String] and
    (__ \ "paymentMethod").read[String] and
    (__ \ "paymentTerm").read[Option[String]]
  ).tupled

  val fields13to22: Reads[(Option[String], String, Option[String], Option[String], Option[Set[CreateOrderRequest]], Option[Seq[CreateTransactionOtherChargeRequest]], Option[Seq[CreateNoteRequest]], Option[Seq[String]], Option[String], Option[String])] = (
    (__ \ "deliveryMethod").read[Option[String]] and
    (__ \ "source").read[String] and
    (__ \ "attachments").read[Option[String]] and
    (__ \ "agent").read[Option[String]] and
    (__ \ "orders").read[Option[Set[CreateOrderRequest]]] and
    (__ \ "otherCharges").read[Option[Seq[CreateTransactionOtherChargeRequest]]] and
    (__ \ "notes").read[Option[Seq[CreateNoteRequest]]] and
    (__ \ "subscribers").read[Option[Seq[String]]] and
    (__ \ "trackingId").read[Option[String]] and
    (__ \ "acquisition").read[Option[String]]
  ).tupled

implicit val readsCreateTransactionRequest: Reads[CreateTransactionRequest] = (fields1to12, fields13to22) {
    case((name, balance, amount, currency, dueDate, orderDate, billing, shipping, status, email, paymentMethod, paymentTerm), (deliveryMethod, source, attachments, agent, orders, otherCharges, notes, subscribers, trackingId, acquisition)) => 
    CreateTransactionRequest(name, balance, amount, currency, dueDate, orderDate, billing, shipping, status, email, paymentMethod, paymentTerm, deliveryMethod, source, attachments, agent, orders, otherCharges, notes, subscribers, trackingId, acquisition)
  }

このリンクからフォローして試したことは確かです。残念ながら、それは機能しておらず、まだエラーが発生しています

誰かが 22 のフィールドを分割する他の方法を提案できますかRead?

4

1 に答える 1