Play-Json | Serialization of Case classes(23 + fields)

Reading Time: 2 minutes


In this blog we discuss about how to Deserialise and Serialise case classes having greater than 22 fields using play-json-extensions.

Library Dependencies

Add the given dependencies to your build.sbt

libraryDependencies += "ai.x" %% "play-json-extensions" % "0.42.0"


As we use play-json for deserialise and serialise case classes in different scala framework like play,akka etc.

Sometimes we encounter the problem for formating these case classes which have more then 22 fields fields.As normal play-json support only maximum 22 fields.

For getting this kind of support for bigger case class we use play-json-extensions.As it provide same suitable support as play-json but it works for bigger case class also(>22 fields).

After that formatting we can use the same procedure as done in play-json for converting json data and case classes.


We check out this feature with the help of the below examples.

import play.api.libs.json.Format


object Main extends App {

case class SampleBiggerClass(      

 val sampleBiggerClass = SampleBiggerClass("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11","a12","a13","a14","a15","a16","a17","a18","a19","a20","a21","a22","a23","a24","a25","a26")

 //Create implicit formatter
 implicit val sampleBiggerClassFormatter : Format[SampleBiggerClass] = Jsonx.formatCaseClass[SampleBiggerClass]

In the given example we define the case class SampleBiggerClass which have 26 fields for using case class we need to define the implicit formatter which uses the Jsonx for formatting the case class.

For this formatting we also the implict NameEncoder so for this we import it from

Now we can use this case class for converting into json or use for differnt purposes.

 val sampleJsonData = Json.toJson(sampleBiggerClass)
 assert(sampleBiggerClass ==[SampleBiggerClass] )

We can also use this library for different purposes like-De-/Serialize tuples,De-/Serialize single value classes,also below given example shows how to deserialize case classes which have default value fields.

deserialization uses default values:-

case class SampleClass(s: String, i: Int = 9)
implicit  valformat:OFormat[SampleClass]=Jsonx.formatCaseClassUseDefaults[SampleClass]
println(assert(SampleClass("akaak",9) == Json.parse("""{"s":"akaak"}""").validate[SampleClass].get))


This blog gives the practical implementation of how to format case class having more than 22 fields.

This librarary is very helpful if you were using play-json and encounter the problem of lage case classes.


Scaladex –


Written by 

Akash Kumar is a Software Consultant at Knoldus Software LLP. He has done from Abdul Kalam Technical University. He is majorly focused on Scala and Angular. On the personnel side, he loves to play Cricket and online video games.