ScalaObjectMapper ClassCastException从json文件读取序列

ScalaObjectMapper ClassCastException从json文件读取序列,json,scala,Json,Scala,我正在使用com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper对json文件中的一系列对象进行反序列化: val mapper = new ObjectMapper() with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) case class MyPair(key: String, value: Double) mapper.readV

我正在使用
com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper对json文件中的一系列对象进行反序列化:

val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)

case class MyPair(key: String, value:  Double)

mapper.readValue(new File("mypairs.json"), classOf[Seq[MyPair]])
mypairs.json

[
{"key":"B","value":0.0},
{"key":"C","value":20.0},
{"key":"A","value":30.0}
]
这导致:

java.lang.ClassCastException: scala.collection.immutable.Map$Map2 cannot be cast to MyPair

我用以下方法解决了这个问题:

mapper.readValue[Seq[MyPair]] (new File("mypairs.json"))
上述方法在ScalaObjectMapper上实现 而引起问题的那个呢

public <T> T readValue(File src, Class<T> valueType)
publictreadvalue(文件src,类valueType)

来自com.fasterxml.jackson.databind.ObjectMapper

我只通过以下方法解决了这个问题:

mapper.readValue[Seq[MyPair]] (new File("mypairs.json"))
上述方法在ScalaObjectMapper上实现 而引起问题的那个呢

public <T> T readValue(File src, Class<T> valueType)
publictreadvalue(文件src,类valueType)

来自com.fasterxml.jackson.databind.ObjectMapper

在scala中使用基于泛型的java方法时会发生类似的问题在scala中使用基于泛型的java方法时会发生类似的问题