如何使用 µPickle 序列化通用案例 类?
How to serialize generic case classes with µPickle?
µPickle docs 说通用案例 类 可以序列化:
Out of the box, uPickle supports writing and reading the following types:
- Stand-alone
case class
es and case object
s, and their generic equivalents,
但是没有给出示例,到目前为止我无法找到正确的方法。我的尝试是:
import upickle.default._
object Container {
implicit def rw[T]: ReadWriter[Container[T]] = macroRW
}
case class Container[T](value: T)
object Main extends App {
val c = new Container(0)
val cString = write(c)
println("c " + cString)
}
失败并出现错误:
Error:(7, 50) could not find implicit value for parameter e:
upickle.default.Reader[T]
implicit def rw[T]: ReadWriter[Container[T]] = macroRW
如何使用 µPickle 序列化一般案例 类?
不要忘记使用上下文绑定
implicit def rw[T: ReadWriter]: ReadWriter[Container[T]] = macroRW
µPickle docs 说通用案例 类 可以序列化:
Out of the box, uPickle supports writing and reading the following types:
- Stand-alone
case class
es andcase object
s, and their generic equivalents,
但是没有给出示例,到目前为止我无法找到正确的方法。我的尝试是:
import upickle.default._
object Container {
implicit def rw[T]: ReadWriter[Container[T]] = macroRW
}
case class Container[T](value: T)
object Main extends App {
val c = new Container(0)
val cString = write(c)
println("c " + cString)
}
失败并出现错误:
Error:(7, 50) could not find implicit value for parameter e:
upickle.default.Reader[T]
implicit def rw[T]: ReadWriter[Container[T]] = macroRW
如何使用 µPickle 序列化一般案例 类?
不要忘记使用上下文绑定
implicit def rw[T: ReadWriter]: ReadWriter[Container[T]] = macroRW