2

我正在尝试使用 Scala-pickling “unpickle” JSON 结构,如下所示:

{"id":1,"aList":[{"x":1}, {"x":2}]}

可悲的是,当使用以下代码进行 unpickling 时:

import scala.pickling._, scala.pickling.Defaults._, json._

val jsonString="""{"id":1,"aList":[{"x":1}, {"x":2}]}"""

case class X(id:Int,aList:List[Y])
case class Y(x:Int)

jsonString.unpickle[X]

我得到以下异常:

scala.MatchError: [{"x" : 1.0}, {"x" : 2.0}] (of class scala.util.parsing.json.JSONArray)
at scala.pickling.json.JSONPickleReader$$anonfun$beginEntry$2.apply(JSONPickleFormat.scala:212)
at scala.pickling.json.JSONPickleReader$$anonfun$beginEntry$2.apply(JSONPickleFormat.scala:203)
at scala.pickling.PickleTools$class.withHints(Tools.scala:521)
at scala.pickling.json.JSONPickleReader.withHints(JSONPickleFormat.scala:170)
at scala.pickling.json.JSONPickleReader.beginEntry(JSONPickleFormat.scala:203)

是否可以将 Scala-pickling 与列表/集合一起使用?

4

0 回答 0