如何通过修改或分支Shapeless并修改MkFieldLens的来源来序列化以下类?
case class IdHolder[T](t: T)(implicit
l: MkFieldLens.Aux[T, Witness.`'id`.T, Option[Long]]){
private def idLens = lens[T] >> 'id
}
运行此测试代码:
case class Cow(sound: String, id: Option[Long])
object Testy extends App {
val s = IdHolder(Cow("moo", Some(123L)))
val tmp = File.createTempFile("save_test", "bin")
val oos = new ObjectOutputStream(new FileOutputStream(tmp))
oos.writeObject(s)
}
产生此错误:
Exception in thread "main" java.io.NotSerializableException: shapeless.MkFieldLens$$anon$33