我有一个像这样的模型类:
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Defect
我需要 JsonInclude.Include.NON_NULL
来忽略 null
值。但有时我有一个属性需要为 null
。
@JsonProperty("blocked")
private String blocked;
有没有一种方法可以动态地(在运行时)将这个值设置为包含或不包含?
最佳答案
您应该能够使用字段级别的@JsonInclude
覆盖类级别的@JsonInclude
,如下所示:
@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonProperty("blocked")
private String blocked;
关于java - 如果在类级别设置了 Include.NON_NULL,则 Jackson 序列化 NULL 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31922636/