I understand that if I have:
case class Person(name: String)
I can use
object PersonJsonImplicits extends DefaultJsonProtocol {
implicit val impPerson = jsonFormat1(Person)
}
and thus serialize it with:
import com.example.PersonJsonImplicits._
import spray.json._
new Person("somename").toJson
however what If i have
trait Animal
case class Person(name: String) extends Animal
and I have somewhere in my code
val animal = ???
and I need to serialize it and I want to use json spray
which serializer should I add I was hoping to have something like:
object AnimalJsonImplicits extends DefaultJsonProtocol {
implicit val impAnimal = jsonFormat???(Animal)
}
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 https://github.com/spray/spray-json and don't understand how to do that..
so how can I serialize the set of
trait Animal
case class Person(name: String) extends Animal
with json spray?