@JsonInclude(Include.NON_NULL) does not remove null fields from Inner POJO

2.2k views Asked by At

I have below response structure. I am using jackson-databind version 2.5.1.

public class MyResponse {
    private String entity;

    private Detail detail;

    // public Getter and setter
}

@JsonInclude(Include.NON_NULL)
public class Detail {
    private String name;

    private String location; // location field is null for testing

    // public Getter and setter
}

Problem: Response includes location field even if it is null.

Note: @JsonInclude works on outer object i.e. MyResponse, but it does not works in inner POJO class.

Thank you.

0

There are 0 answers