我正在使用 json4s 序列化一些 scala 映射对象。
import org.apache.spark.util.StatCounter
import org.json4s.DefaultFormats
val m: scala.collection.Map[String, Map[String, StatCounter]] = Map("key" -> Map("secondKey" -> StatCounter()))
implicit val format = DefaultFormats
import org.json4s.jackson.Serialization.write
println(m)
println(write(m))
正确的结果是:
Map(key -> Map(secondKey -> (count: 0, mean: 0,000000, stdev: NaN, max: -Infinity, min: Infinity)))
奇怪的是我只得到序列化类
{"key":{"secondKey":{}}}
res1: Unit = ()
如何正确序列化?