我有自己的自定义DateTime类,为此我编写了以下自定义作家和读者:
val dtWriter = Writer[DateTime]{
case t => Js.Str(format(t))
}
val dtReader = Reader[DateTime]{
case Js.Str(time) =>
try {
parse(time)
}
catch {
case _: Exception =>
SDateTime(0)
}
}
但是,我尝试将软件包版本从0.4.4升级到0.7.1,并且此代码不再编译,出现以下错误:
错误:(7,8)对象Js不是包upickle的成员
导入upickle.Js
错误:(112,23)对象Writer不接受类型参数。
val dtWriter = Writer [DateTime] {
如何用最新版本的upickle重写它?
答案 0 :(得分:1)
仅基于阅读http://www.lihaoyi.com/upickle/#CustomPicklers:
val dtRW = readwriter[String].bimap[DateTime](
t => format(t), // also `format _` or just `format` should work
time =>
try {
parse(time)
}
catch {
case _: Exception =>
SDateTime(0)
}
)