我的目标是将jsonObject转换为Class。我想只添加在Class中被赋值的字段。例如:json对象包含50个字段。类有4个领域。我想只映射确切的4个字段,而不需要在类中添加46个添加忽略。Jackson ObjectMapper忽略所有没有注释的属性
JSON:
{
"id": "1",
"name": "John",
"Address": "Some Address 7009",
}
类别:
public static class User {
Integer id;
String name;
public User (@JsonProperty("id")Integer id, @JsonProperty("name")String name {
this.id= id;
this.name= name;
}
....
}
用户类没有地址字段。我的目标是排除它,因为它没有注释。
您需要为您不想要的剩余属性添加@JsonIgnore – Nimesh
您是否阅读我的问题? – TeodorKolev
这是不可能的。你可以在剩下的属性上分配@JsonIgnore,或者你可以做周转,你可以改变json键不匹配对象属性,反之亦然。 – Nimesh