<dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-scala_2.13</artifactId> <version>2.12.2</version> </dependency> import com.fasterxml.jackson.module.scala.DefaultScalaModule; import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper().registerModule(new DefaultScalaModule()); scala import com.fasterxml.jackson.databind.ObjectMapper case class Person(name: String, age: Int) val mapper: ObjectMapper = new ObjectMapper().registerModule(DefaultScalaModule) val person: Person = Person("John", 25) val jsonString: String = mapper.writeValueAsString(person) val json: String = """{"name":"Jane","age":30}""" val personObj: Person = mapper.readValue(json, classOf[Person])


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