我已经多次使用 Json Write 和 Read,但是这次出现了一个愚蠢的错误,我在那里找不到任何拼写错误..请在这里帮助我.. ^^
Overloaded method value [apply] cannot be applied to (models.Expense_PIheader => (String, java.util.Date, String, String, Integer))
这是我的案例类:
case class Expense_PIheader(pi_id: String, pi_due_date: Date, supplier_id: String, staff_id: String, status: Integer)
这是我的 JSON:
object Expense_PIheader {
implicit val ExpensePIheaderWrites: Writes[Expense_PIheader] = (
(JsPath \ "pi_id").write[String] and
(JsPath \ "pi_due_date").write[Date] and
(JsPath \ "supplier_id").write[String] and
(JsPath \ "staff_id").write[String] and
(JsPath \ "status").write[Int]
)(unlift(Expense_PIheader.unapply))
implicit val ExpensePIheaderReads: Reads[Expense_PIheader] = (
(JsPath \ "pi_id").read[String] and
(JsPath \ "pi_due_date").read[Date] and
(JsPath \ "supplier_id").read[String] and
(JsPath \ "staff_id").read[String] and
(JsPath \ "status").read[Int]
)(Expense_PIheader.apply _)
}
最佳答案
您的案例类有一个类型为Integer
的status 字段。
写入和读取需要一个Int
类型的status 字段。
更改一个或另一个以使类型匹配并且它将起作用。
关于json - Play Framework, JSON 重载方法值 [申请],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23358963/