title: Ignore null fields and empty fields/arrays with Jackson
body: <p>My project builds on jdk1.6.0_141 and I am currently using jackson 2.7.9.below is the class that use to marshal the object.</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonInclude;
  
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  public class Employee{
  
      private String number;
      private String department;
      private List&lt;Project&gt; projects;
  
      //getters and setters goes here
  } 
  </code></pre>
  
  <p>I have added the below dependencies in my pom file </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
       &lt;version&gt;2.7.9&lt;/version&gt;
  &lt;/dependency&gt;       
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
      &lt;version&gt;2.7.9&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
      &lt;version&gt;2.7.9&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I want to remove the null values and empty arrays from my result which is a json string but the null values are not getting removed. I even used </p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
  </code></pre>
  
  <p>but the result is still the same. I applied the same for anothe rproject which builds in JDK 8 and the version of jackson is 2.9.2 and in the response, it removes all nulls and emty fields and arrays just by adding NON_EMPTY only.</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_EMPTY)
  </code></pre>
  
  <p>Can someone please guide me the reason why I am not getting the expected results.How can I use the JsonInclude properly to skip all the nulls, empty fields and empty arrays.</p>
  
  <p>This is the method that I invoke to load the json file from the resources folder and parse</p>
  
  <pre><code>    InputStream in = getClass().getResourceAsStream(
              "/EmployeeFile.json");
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      byte[] buffer = new byte[1024];
      int len;
  
      while ((len = in.read(buffer)) != -1) {
          os.write(buffer, 0, len);
      }
      Employee emp = JSONUtil.toObject(os.toByteArray());
  </code></pre>
  
  <p>Object mapper</p>
  
  <pre><code>public static Employee toObject(byte[] jsonData) throws IOException {
      Employee emp = null;
      ObjectMapper objectMapper = new ObjectMapper();
      emp = objectMapper.readValue(jsonData, Employee.class);         
      return emp;
  }
  </code></pre>