将JSON反序列化为Map [String,Option [String]]

时间:2016-12-03 18:31:20

标签: scala jackson jackson-module-scala

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]]的最佳方法是什么?

0 个答案:

没有答案