LivingRobot
LivingRobot

Reputation: 913

Serializing Case Class

This is kind of a strange issue I've been having. I had a case class with many parameters, including a string, and was able to serialize it to JSON straightforwardly using Play's Format. Then, I added another parameter - a String - and it starts complaining that

No unapply or unapplySeq function found

The original looked like this:

case class PushMessage(stageOne: Boolean, stageTwo: Boolean, stageThree: Boolean, stageFour: Boolean, stageFive: Boolean,
                   highestStage: Int, iOSTotal: Int, androidTotal: Int, iOSRunningCount: Int, androidRunningCount: Int,
                   vendorId: String, androidProblem: Boolean, iOSComplete: Boolean, androidComplete: Boolean,
                   totalStageThrees: Int, totalStageFours: Int, totalStageFives: Int, expectedTotals: Int,
                   latestUpdate: Long, iOSProblem: Boolean, startTime: Long, date: Long)

The new one looks like

case class PushMessage(stageOne: Boolean, stageTwo: Boolean, stageThree: Boolean, stageFour: Boolean, stageFive: Boolean,
                   highestStage: Int, iOSTotal: Int, androidTotal: Int, iOSRunningCount: Int, androidRunningCount: Int,
                   vendorId: String, androidProblem: Boolean, iOSComplete: Boolean, androidComplete: Boolean,
                   totalStageThrees: Int, totalStageFours: Int, totalStageFives: Int, expectedTotals: Int,
                   latestUpdate: Long, iOSProblem: Boolean, startTime: Long, date: Long, topics: String)

The only difference is the parameter topics.

My serializer looks like:

    object PushMessage {

  implicit val pushMessageFormat = Json.format[PushMessage]

}

Any and all help would be appreciated. Thanks.

Upvotes: 0

Views: 121

Answers (1)

Markus1189
Markus1189

Reputation: 2869

Play uses macros and tuples to derive the Json instance. The problem is that tuples are limited to 22 fields in Scala (at least at the moment).

That means that Play won't be able to automatically derive a Json instance, although you can work around it by manually writing it.

You can find more info here: Play Framework Scala format large JSON (No unapply or unapplySeq function found)

Upvotes: 3

Related Questions