import com.fasterxml.jackson.module.scala.DefaultScalaModule; import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new DefaultScalaModule()); import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.scala.DefaultScalaModule; case class Person(name: String, age: Int) object SerializationExample { def main(args: Array[String]): Unit = { val objectMapper = new ObjectMapper() objectMapper.registerModule(DefaultScalaModule) val person = Person("John Doe", 30) val jsonString = objectMapper.writeValueAsString(person) println(jsonString) val deserializedPerson = objectMapper.readValue(jsonString, classOf[Person]) println(deserializedPerson) } }


上一篇:
下一篇:
切换中文