public class MyDto {
@JsonInclude(Include.NON_NULL)
private String stringValue;
private int intValue; // standard getters and setters
}
public class Object {
@JsonInclude(NON_NULL)
@JsonProperty("property")
private String property;
}
mapper.setSerializationInclusion(Include.NON_NULL);
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonInclude(Include.NON_NULL)
public String getStudentName() {
return studentName;
}
(or)
@JsonInclude(Include.NON_NULL)
public void setStudentName(String studentName) {
this.studentName = studentName;
}
mapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
mapper.setSerializationInclusion(Include.NON_NULL);