【发布时间】:2016-03-07 11:37:07
【问题描述】:
case class CustomerInfo (
customerId: Long,
customerName: String,
cameAt: String,
staffId:String,
staffName:String
)
case class CustomerResult (
customers:Option[Seq[CustomerInfo]] = None
){
def toJson = Json.toJson(this)
}
implicit val customerInfoWrites: Writes[CustomerInfo] = (
(JsPath \ "customer_id").write[Long] and
(JsPath \ "customer_name").write[String] and
(JsPath \ "came_at").write[String] and
(JsPath \ "staff_id").write[String] and
(JsPath \ "staff_name").write[String]
)(unlift(CustomerInfo.unapply))
implicit val custmerResultWrites: Writes[CustomerResult] = (
(JsPath \ "customers").writeNullable[Seq[CustomerInfo]]
)(unlift(CustomerResult.unapply))
第二种方法是错误 custmerResultWrites,因为它只有一个 JsPath 写入。如果我在 CustomerResult 中再添加一个部分,则错误是可以的。 错误:
found : CustomersSearchResult.this.CustomerResult => Option[Seq[CustomersSearchResult.this.CustomerInfo]]
required: play.api.libs.json.Writes[Seq[CustomersSearchResult.this.CustomerInfo]]
【问题讨论】:
标签: scala playframework playframework-2.0