title: how to serialize case classes with traits with jsonspray
body: <p>I understand that if I have:</p>
  
  <pre><code>case class Person(name: String)
  </code></pre>
  
  <p>I can use </p>
  
  <pre><code>object PersonJsonImplicits extends DefaultJsonProtocol {
    implicit val impPerson = jsonFormat1(Person)
  }
  </code></pre>
  
  <p>and thus serialize it with:</p>
  
  <pre><code>import com.example.PersonJsonImplicits._
  import spray.json._
  new Person("somename").toJson
  </code></pre>
  
  <p>however what If i have</p>
  
  <pre><code>trait Animal
  case class Person(name: String) extends Animal
  </code></pre>
  
  <p>and I have somewhere in my code</p>
  
  <pre><code>val animal = ???
  </code></pre>
  
  <p>and I need to serialize it and I want to use json spray</p>
  
  <p>which serializer should I add I was hoping to have something like:</p>
  
  <pre><code>object AnimalJsonImplicits extends DefaultJsonProtocol {
    implicit val impAnimal = jsonFormat???(Animal)
  }
  </code></pre>
  
  <p>where maybe I needed to add some matcher in order to check of what type is Animal so that if its a person I would direct it to person but found nothing... was reading <a href="https://github.com/spray/spray-json">https://github.com/spray/spray-json</a>  and don't understand how to do that..</p>
  
  <p>so how can I serialize the set of </p>
  
  <pre><code>trait Animal
  case class Person(name: String) extends Animal
  </code></pre>
  
  <p>with json spray?</p>