当前位置: 首页 > 工具软件 > JSON in Java > 使用案例 >

jackson 序列化忽略未知字段: How to Ignore Unknown Properties While Parsing JSON in Java

宰父俊彦
2023-12-01

One of the common problem while parsing JSON in Java using Jackson API is that it fails when your JSON contains unknown properties i.e. your Java class doesn't have all the field corresponding to all JSON properties.

使用 Jackson API 在Java中解析JSON时的一个常见问题是,当JSON包含未知属性时,即Java类没有与所有JSON属性对应的所有字段时,解析失败。

Anyway, it was our fault that we didn't review code properly and allowed him to release his code into production without handling unknown files. The issue could have simply been avoided if he was familiar with Jackson library in a little bit more detail.

Jackson API provides two ways to ignore unknown fields, first at the class level using @JsonIgnoreProperties annotation and second at the ObjectMapper level using configure() method.

You will see both approaches in this article and learn how to use them and when to use @JsonIgnoreProperties and when to ignore unknown

 类似资料: