看起来当我尝试序列化从 Seq 扩展的案例类时,它会作为 Seq 处理,并且所有其他字段都被省略了。
序列化只会导致没有附加字段的标准序列。而反序列化失败。
有人知道我在这里做错了什么吗?
代码:
// Definition of class
case class IntSeq(count: Int, ints: Seq[Int]) extends Seq[Int] {
def length: Int = ints.length
def iterator: Iterator[Int] = ints.iterator
def apply(idx: Int) = ints(idx)
}
// type Hints
implicit val hints = Serialization.formats( ShortTypeHints(List(classOf[IntSeq])) )
lazy val testIntSeq = IntSeq(5, List(1,2,3,4,5))
val ser = Serialization.write[IntSeq](testIntSeq)
// ser: String = [1,2,3,4,5]
Serialization.read[IntSeq](ser) // Hurray: org.json4s.package$MappingException: unknown error