0
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]] に逆シリアル化する最良の方法は何ですか?

4

0 に答える 0