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?
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
Json.format[TestResponse]
}
}