我正在尝试找到一种方法来使用内置的Macro Json Writer来序列化Seq [(String,Customer)]
我设法为Seq [Customer]做了这个,但是当添加touple时,编译器开始尖叫我.
此代码有效:
package models.health
import play.api.libs.json._
case class Customer(name: String, age: Int)
//we use the dummy var as a workaround to the json writer limitations (cannot handle single argument case class)
case class Demo(customers: Seq[Customer], dummy: Option[String] = None)
object Demo {
import play.api.libs.functional.syntax._
implicit val customer_writer = Json.writes[Customer]
implicit val writes: Writes[Demo] = (
(__ \ "customers").write[Seq[Customer]] and
(__ \ "dummy").writeNullable[String]) {
(d: Demo) => (d.customers,d.dummy)
}
}
Run Code Online (Sandbox Code Playgroud)
但是下面的代码(只需从Seq [Customer]更改为Seq [(String,Customer)]不会Copmile ...真的很感激任何帮助:
package models.health …Run Code Online (Sandbox Code Playgroud)