Say I have a model like this:
case class Items(typeOfItems: TypeOfItems)
object Items{
implicit val format = Json.format[Items]
}
sealed trait TypeOfItems extends Product with Serializable
object TypeOfItems {
final case class Toy(typeOfItem : String, name : String, price : Int) extends TypeOfItems
final case class Car(typeOfItem : String, model: String, price : Int ) extends TypeOfItems
}
I cannot do any serialising or deserialising. I get the following errors:
No instance of play.api.libs.json.Format is available for model.TypeOfItems in the implicit scope (Hint: if declared in the same file, make sure it's declared before)
[error] implicit val format = Json.format[Items]
[error] ^
[error] No Json serializer found for type model.Items. Try to implement an implicit Writes or Format for this type.
[error] Ok(Json.toJson(Items(Toy("Toy", "Doll", 2))))
I am not sure how to specify the formats for TypeOfItems. How do I do that?