val mapper = new ObjectMapper
mapper.registerModule(DefaultScalaModule)
val original: Map[String, Option[String]] = Map[String, Option[String]]("key" -> Some("value"))
val json: ObjectNode = new ObjectNode(JsonNodeFactory.instance).put("key", "value")
val converted = mapper.convertValue(json, classOf[Map[String, Option[String]]])
println(s"JSON: $json")
println(s"original: $original")
println(s"converted: $converted, equals original " + (if (converted == original) "TRUE" else "FALSE"))
打印
JSON: {"key":"value"}
original: Map(key -> Some(value))
converted: Map(key -> value), equals original FALSE
反序列化为Map [String,Option [String]]的最佳方法是什么?