Issue with Play Serialization for nested types

Version: 2.6

I have the below case class

case class TestResponse(id: Seq[Option[String]])

object TestResponse {
implicit val testResponseFormat= Json.format[TestResponse]

While compiling, I keep on getting the error:

No instance of play.api.libs.json.Format is available for scala.collection.immutable.Seq[scala.Option[java.lang.String]] in the implicit scope (Hint: if declared in the same file, make sure it’s declared before)

Is this supported in play or am I missing something?

@aironm Pls check this section on JSON serialization. Has examples for complex types.


Thanks Aditya for the reply.

After some debugging the issue turned out to be how play sequences the implicits for Formats. Since I had Seq[Option[String]], it was failing as it was not able to find Option format since it is defined after the Seq format. I explicitly provided the Format[Option[String]].

object TestResponse {
implicit val testResponseFormat= {
   implicit val optionFormat: Format[Option[String]] = Format.optionWithNull
1 Like