Custom type discriminator on nested json

Hi,

I have such nested json with its own naming strategy see documentation

        {
          "admTpe":"client",
          "organization":"Bar",
          "child": [
             {"admTpe":"client","organization":"bar"}, 
             {"admTpe":"contributor","organization":"bar"}
          ]
        }

I d’like them mapped to those case class (a tree of case class):

  sealed trait Role
  case class Contributor(organization: String) extends Role
  case class Client(organization: String, child: Option[Seq[Role]]) extends Role

Sadly I haven’t find out how to do this. Here is my code right now:

import play.api.libs.json.Json
import org.junit.Test

class spec {

  @Test
  def theTest {

    val contributorJson = Json.parse("""
        {
          "admTpe":"contributor",
          "organization":"Foo"
        }
      """)
    val clientJson =
      Json.parse("""
        {
          "admTpe":"client",
          "organization":"Bar",
          "child": [
             {"admTpe":"client","organization":"bar"},
             {"admTpe":"contributor","organization":"bar"}
          ]
        }
      """)

    //#auto-JSON-custom-trait
    import play.api.libs.json._

    implicit val cfg = JsonConfiguration(
      // Each JSON objects is marked with the admTpe, ...
      discriminator = "admTpe",
      // ... indicating the lower-cased name of sub-type
      typeNaming = JsonNaming { fullName =>
        fullName.drop(66 /* remove pkg */ ).toLowerCase
      }
    )

    // First provide instance for each sub-types 'client' and 'Contributor':
    implicit val contributorRead = Json.reads[Contributor]
    implicit val clientRead = Json.reads[Client]
    // Finally able to generate format for the sealed family 'Role'
    implicit val roleRead = Json.reads[Role]

    def readAnyRole(input: JsValue): JsResult[Role] = input.validate[Role]
    def getRole(result: Role) = result match {
      case e: Contributor => println("contributor")
      case e: Client      => println("client"); println(e.toString)
      case _              => println("jim")
    }

    getRole(readAnyRole(contributorJson).get)
    getRole(readAnyRole(clientJson).get)

  }

  sealed trait Role

  case class Contributor(organization: String) extends Role
  case class Client(organization: String, child: Option[Seq[Role]]) extends Role

}