Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson serialize NULL property value if Include.NON_NULL is set at class level

I have a model class like this:

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Defect

and I need JsonInclude.Include.NON_NULL to ignore the null values. But I have a property that needs to be null sometimes.

@JsonProperty("blocked")
private String blocked;

Is there a way I can dynamically (at run-time) set this value to be included or not?

like image 543
Advicer Avatar asked Dec 24 '22 16:12

Advicer


1 Answers

You should be able to override the class-level @JsonInclude with a field-level @JsonInclude, as follows:

@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonProperty("blocked")
private String blocked;
like image 172
heenenee Avatar answered Dec 27 '22 11:12

heenenee