说我有一个这样的模型:
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
}
我无法进行任何序列化或反序列化。我收到以下错误:
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))))
我不确定如何为TypeOfItems指定格式。我怎么做?