我有这个案例课
case class Contact(id: String, firstName: String, lastName: String)
当三个字段中的任何一个丢失时,我希望 Jackson Scala 对象映射器失败,例如:
val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.readValue[Contact](""""{"id":"123","firstName":"John"}""")
但是当在 Json 字符串中给出附加字段时成功,例如:
mapper.readValue[Contact](""""{"id":"123","firstName":"John","lastName":"Test","age":"24"}""")
我确实尝试过使用@JsonIgnoreProperties(ignoreUnknown = true)
, mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
但是这两个选项似乎都禁用了整个验证,而不仅仅是忽略了其他字段。