【发布时间】:2016-09-02 03:37:33
【问题描述】:
我有以下案例类
case class UserId(value: String) extends MappedTo[String]
(MappedTo是slick.typesafe的通用id case类)
我在 json4s 中声明了它的序列化器
case object IdSerializer extends CustomSerializer[UserId](format => ( {
case JString(s) => UserId(s)
case JNull | JNothing => null
}, {
case i: UserId => JString(i.value)
case JNull | JNothing => null
}))
问题是我有超过 20 个这样的 id 字段,我不想为每个字段声明序列化程序。有没有办法为MappedTo 做它,以便它可以应用于它的所有子类?
【问题讨论】:
标签: scala serialization slick json4s