我是 scala 的新手,并试图将我的 json 映射到一个对象。我找到了 jackson-scala-module 但无法弄清楚如何使用它。一个小例子可能会有所帮助。
val json = { "_id" : "jzcyluvhqilqrocq" , "DP-Name" : "Sumit Agarwal" , "DP-Age" : "15" , "DP-height" : "115" , "DP-weight" : "68"}
我想将此映射到Person(name: String, age: Int, height: Int, weight: Int)
直到现在我一直在尝试使用这个:
import com.fasterxml.jackson.databind.ObjectMapper
Val mapper = = new ObjectMapper();
val data = mapper.readValue(json, classOf[Person])
我正在使用的依赖项:
"com.fasterxml.jackson.module" % "jackson-module-scala_2.11" % "2.8.4"
我错过了什么吗?
编辑:
[error] (run-main-4) com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of models.Person: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)