更新时间:2022-03-14 23:24:52
我认为你想要的是
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Person {
...
}
这是Jackson 1.x的方式。我认为在2.x中有一种新的方式。类似
that's the Jackson 1.x way. I think there's a new way in 2.x. Something like
@JsonInclude(Include.NON_NULL)
public class Person {
...
}
这些将告诉Jackson只序列化非空值,不要抱怨反序列化缺失值时。我认为它只会将其设置为Java默认值。
These will tell Jackson to only serialize values that are not null, and don't complain when deserializing a missing value. I think it will just set it to the Java default.