I'm trying to write a Read/Write value for a case class for which many of the values might be null. Following the Play Framework's tutorials I write it as
implicit val incomingMessageWrites: Writes[IncomingMessage] = (
(JsPath \ "stageNum").write[Int] and
(JsPath \ "stage").write[String] and
(JsPath \ "stageTime").write[Long] and
(JsPath \ "vendorId").write[String] and
(JsPath \ "text").writeNullable[String] and
(JsPath \ "campaignCode").writeNullable[String] and
(JsPath \ "osTotals").writeNullable[OSTotals] and
(JsPath \ "splitSegment").writeNullable[Int] and
(JsPath \ "segmentNum").writeNullable[Int] and
(JsPath \ "osBatchStatus").writeNullable[OSBatchStatus]
)(unlift(IncomingMessage.unapply))
However, I keep encountering the same issue where IntelliJ tells me that the uplift method doesn't work because "Application Does Not Take Parameters".
The case class for this is
case class IncomingMessage(
stageNum: Int,
stage: String,
stageTime: Long,
vendorId: String,
text: String,
campaignCode: String,
osTotals: OSTotals,
splitSegment: Int,
segmentNum: Int,
osBatchStatus: OSBatchStatus) {
def this(stageNum: Int, stage: String, stageTime: Long, vendorId: String, text: String, campaignCode: String) =
this(stageNum, stage, stageTime, vendorId, text, campaignCode, null, 0, 0, null)
def this(stageNum: Int, stage: String, stageTime: Long, splitSegment: Int, vendorId: String, text: String, campaignCode: String) =
this(stageNum, stage, stageTime, vendorId, text, campaignCode, null, splitSegment, 0, null)
def this(stageNum: Int, stage: String, stageTime: Long, segmentNum: Int, vendorId: String) =
this(stageNum, stage, stageTime, vendorId, null, null, null, 0, segmentNum, null)
def this(stageNum: Int, stage: String, stageTime: Long, segmentNum: Int, vendorId: String, osTotals: OSTotals) =
this(stageNum, stage, stageTime, vendorId, null, null, osTotals, 0, segmentNum, null)
def this(stageNum: Int, stage: String, stageTime: Long, vendorId: String, oSBatchStatus: OSBatchStatus) =
this(stageNum, stage, stageTime, vendorId, null, null, null, 0, 0, osBatchStatus)
}
The same thing happens for the other case class
case class OSBatchStatus(os: String, success: Int, failure: Int)
object OSBatchStatus {
implicit val oSBatchStatusReads: Reads[OSBatchStatus] = (
(JsPath \ "os").readNullable[String] and
(JsPath \ "success").readNullable[Int] and
(JsPath \ "failure").readNullable[Int]
)(OSBatchStatus.apply _)
}
I've written Read and Write values, but have omitted them to save space.
Any and all help would be greatly appreciated.