Parsing Json with implicit reads for sequences


I’m trying to follow the scala JSON Reads/Writes/Format Combinators documentation for version 2.8.x.

When creating implicit reads for my case classes I have problems when the case class contains a Seq. It cannot find implicits for the Seq containing objects from my case class.

This is my code:

// from maven repo
// - play-json - 2.8.1
import play.api.libs.json._
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._

object MyPlayJsonTest {
  def main(args: Array[String]): Unit = {
    val top3FemaleNames =
        "number" -> 3,
        "names" -> Json.arr(
          Json.obj("number" -> 1, "name" -> "Mary"),
          Json.obj("number" -> 1, "name" -> "Patricia"),
          Json.obj("number" -> 1, "name" -> "Jennifer")

    case class FemaleName(number: Int, name: String)
    case class ListOfFemaleNames(names: Seq[FemaleName])

    implicit val femaleNameReads: Reads[FemaleName] = (
      (JsPath \ "number").read[Int] and
        (JsPath \ "name").read[String]
      )(FemaleName.apply _)

    implicit val listOfFemaleNamesReads: Reads[ListOfFemaleNames] = (
      (JsPath \ "number").read[Int] and
        (JsPath \ "names").read[Seq[FemaleName]]
    )(ListOfFemaleNames.apply _)

    top3FemaleNames.validate[ListOfFemaleNames] match {
      case JsSuccess(listOfFemaleNames, _) => listOfFemaleNames.names.foreach(println)
      case _: JsError => println("Could not read json")

It cannot compile the line

(JsPath \ "names").read[Seq[FemaleName]]

Because it only has implicits for Int, String (from the std lib) and FemaleName, but not for Seq[FemalName].

This case is derived from the documentation here. Under the section Putting it all together you can find similar code with line

(JsPath \ "residents").read[Seq[Resident]]

Where does it find the implicit for Seq[Resident] in this case, or what is wrong with my example that it can’t find it for Seq[FemalName]?

Cheers, Folux