如果在类级别设置Include.NON_NULL,Jackson会序列化NULL属性值

Adv*_*cer 4 java serialization json jackson

我有这样的模型类:

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Defect
Run Code Online (Sandbox Code Playgroud)

我需要JsonInclude.Include.NON_NULL忽略这些null价值观.但我null有时需要一个属性.

@JsonProperty("blocked")
private String blocked;
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以动态(在运行时)将此值设置为包含或不包含?

hee*_*nee 10

您应该能够@JsonInclude使用字段级别覆盖类级别@JsonInclude,如下所示:

@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonProperty("blocked")
private String blocked;
Run Code Online (Sandbox Code Playgroud)