Java – @JsonInclude(Include.NON_NULL) not working/ jackson serializing null values


I have placed the annotation over the class/pojo and also configured the mapper, but it still serialize null values

I am using Hibernate 4.3.7Final and Jackson 2.4.4. The collections are lazy loaded

Pojo : Removed getter and setters

public class School {

    private int id;

    @OneToMany(cascade=CascadeType.ALL,fetch= FetchType.LAZY)
    private List<Student> students;

    @OneToMany(cascade=CascadeType.ALL,fetch= FetchType.LAZY)
    private List<Employee> staff;



public class JSONMapper extends ObjectMapper {
    private static final long serialVersionUID = -3131980955975958812L;


    public JSONMapper() {

        Hibernate4Module hm = new Hibernate4Module();
        configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        configure(SerializationFeature.INDENT_OUTPUT , false);
        configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);

Output :


Best Solution

Try using JsonInclude.NON_EMPTY instead.