-2
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添加一個部分,錯誤是可以的。 錯誤:playframework json write quesstion
found : CustomersSearchResult.this.CustomerResult => Option[Seq[CustomersSearchResult.this.CustomerInfo]]
required: play.api.libs.json.Writes[Seq[CustomersSearchResult.this.CustomerInfo]]
哦,三江源這麼多,我有我的resovle問題 – haiyang