我的理解是,杰克逊DefaultScalaModule
应该能够开箱即用地阅读 scala 案例类。但只要我给它一个以上的字段,它似乎就会窒息:
val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
scala> mapper.readValue("""{"foo": "bar", "bar": "foo"}""", classOf[Map[String, String]])
res98: Map[String,String] = Map(foo -> bar, bar -> foo)
class Foo(foo: String)
scala> mapper.readValue("""{"foo": "bar"}""", classOf[Foo])
res101: Foo = Foo(bar)
class Foo(foo: String, bar: String)
scala> mapper.readValue("""{"foo": "bar", "bar": "foo"}""", classOf[Foo])
com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name 'foo' (in class Foo)
at [Source: {"foo": "bar", "bar": "foo"}; line: 1, column: 1]
有什么想法吗?