- 상황
- data mode 수정
- 이미 22개의 parameter를 가진 final case class에 parameter 하나 더 추가 필요
- case class는 2.11.x 이후 22개 제한이 해결되어 추가 가능
- 하지만 json de/serializer를 implicit val로 구현하는데, 이게 function call이라 parameter 22개 제한 때문에 그냥 추가는 불가능(compile error)
- 해결
- ref
-
-
Save hyunjun/3807ba075422376ad56490642847d05c to your computer and use it in GitHub Desktop.
Scala Play
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final case class MetaData( | |
messageType: MessageType = MessageType.Regular, | |
messageTags: Seq[MessageTag] = Seq.empty, | |
targetOnly: Boolean = false, | |
markUnread: Option[Boolean] = None, | |
sms: Boolean = false, | |
push: Boolean = true, | |
email: Boolean = true, | |
line: Boolean = false, | |
escalated: Boolean = false, | |
initial: Boolean = false, | |
firstResponse: Boolean = false, | |
noTranslate: Boolean = false, | |
offerId: Option[Long] = None, | |
experimentRunId: Option[Long] = None, | |
expiryDays: Option[Int] = None, | |
shortMessage: Option[String] = None, | |
pushHeader: Option[String] = None, | |
pushMessage: Option[String] = None, | |
pushUrl: Option[String] = None, | |
pushButtons: Option[Seq[PushButton]] = None, | |
forceEnablePush: Boolean = false, | |
emailContext: Option[EmailContext] = None, | |
attachmentItems: Option[Seq[CephAttachmentItem]] = None | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.libs.functional.syntax.{unlift, _} | |
... | |
val metaDataFormat1: OFormat[( | |
MessageType, | |
Seq[MessageTag], | |
Boolean, | |
Option[Boolean], | |
Boolean, | |
Boolean, | |
Boolean, | |
Boolean, | |
Boolean, | |
Boolean, | |
Boolean, | |
Boolean)] = | |
((JsPath \ "message_type") | |
.formatNullable[MessageType] | |
.inmap[MessageType](_.getOrElse(MessageType.Regular), Some.apply _) and | |
(JsPath \ "message_tags").formatWithDefault(Seq.empty[MessageTag]) and | |
(JsPath \ "target_only") | |
.formatNullable[Boolean] | |
.inmap(falseIfNull, nullIfFalse) and | |
(JsPath \ "mark_unread").formatNullable[Boolean] and | |
(JsPath \ "sms") | |
.formatNullable[Boolean] | |
.inmap[Boolean](falseIfNull, Some.apply _) and | |
(JsPath \ "push") | |
.formatNullable[Boolean] | |
.inmap[Boolean](trueIfNull, Some.apply _) and | |
(JsPath \ "email") | |
.formatNullable[Boolean] | |
.inmap[Boolean](trueIfNull, Some.apply _) and | |
(JsPath \ "line") | |
.formatNullable[Boolean] | |
.inmap[Boolean](falseIfNull, nullIfFalse) and | |
(JsPath \ "escalated") | |
.formatNullable[Boolean] | |
.inmap(falseIfNull, nullIfFalse) and | |
(JsPath \ "initial") | |
.formatNullable[Boolean] | |
.inmap[Boolean](falseIfNull, nullIfFalse) and | |
(JsPath \ "first_response") | |
.formatNullable[Boolean] | |
.inmap[Boolean](falseIfNull, nullIfFalse) and | |
(JsPath \ "no_translate") | |
.formatNullable[Boolean] | |
.inmap[Boolean](falseIfNull, nullIfFalse)).tupled | |
val metaDataFormat2: OFormat[( | |
Option[Long], | |
Option[Long], | |
Option[Int], | |
Option[String], | |
Option[String], | |
Option[String], | |
Option[String], | |
Option[Seq[PushButton]], | |
Boolean, | |
Option[EmailContext], | |
Option[Seq[CephAttachmentItem]])] = | |
((JsPath \ "offer_id").formatNullable[Long] and | |
(JsPath \ "experiment_run_id").formatNullable[Long] and | |
(JsPath \ "expiry_days").formatNullable[Int] and | |
(JsPath \ "short_message").formatNullable[String] and | |
(JsPath \ "push_header").formatNullable[String] and | |
(JsPath \ "push_message").formatNullable[String] and | |
(JsPath \ "push_url").formatNullable[String] and | |
(JsPath \ "push_buttons").formatNullable[Seq[PushButton]] and | |
(JsPath \ "force_enable_push") | |
.formatNullable[Boolean] | |
.inmap[Boolean](falseIfNull, nullIfFalse) and | |
(JsPath \ "email_context").formatNullable[EmailContext] and | |
(JsPath \ "attachment").formatNullable[Seq[CephAttachmentItem]]).tupled | |
implicit val f18: Format[MetaData] = (metaDataFormat1 ~ metaDataFormat2)( | |
{ | |
case ( | |
( | |
messageType, | |
messageTag, | |
targetOnly, | |
markUnread, | |
sms, | |
push, | |
email, | |
line, | |
escalated, | |
initial, | |
firstResponse, | |
noTranslate), | |
( | |
offerId, | |
experimentRunId, | |
expiryDays, | |
shortMessage, | |
pushHeader, | |
pushMessage, | |
pushUrl, | |
pushButtons, | |
forceEnablePush, | |
emailContext, | |
attachmentItems) | |
) => | |
new MetaData( | |
messageType, | |
messageTag, | |
targetOnly, | |
markUnread, | |
sms, | |
push, | |
email, | |
line, | |
escalated, | |
initial, | |
firstResponse, | |
noTranslate, | |
offerId, | |
experimentRunId, | |
expiryDays, | |
shortMessage, | |
pushHeader, | |
pushMessage, | |
pushUrl, | |
pushButtons, | |
forceEnablePush, | |
emailContext, | |
attachmentItems) | |
}, | |
(metaData: MetaData) => | |
( | |
( | |
metaData.messageType, | |
metaData.messageTags, | |
metaData.targetOnly, | |
metaData.markUnread, | |
metaData.sms, | |
metaData.push, | |
metaData.email, | |
metaData.line, | |
metaData.escalated, | |
metaData.initial, | |
metaData.firstResponse, | |
metaData.noTranslate), | |
( | |
metaData.offerId, | |
metaData.experimentRunId, | |
metaData.expiryDays, | |
metaData.shortMessage, | |
metaData.pushHeader, | |
metaData.pushMessage, | |
metaData.pushUrl, | |
metaData.pushButtons, | |
metaData.forceEnablePush, | |
metaData.emailContext, | |
metaData.attachmentItems)) | |
) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment