title: Exclude empty Arrays from Jackson ObjectMapper
body: <p>I am building JSON from Java object tree using <a href="http://jackson.codehaus.org/1.8.8/javadoc/org/codehaus/jackson/map/ObjectMapper.html" rel="nofollow noreferrer">Jackson ObjectMapper</a>. Some of my Java objects are collections and sometimes they might be empty. So if they are empty that ObjectMapper generates me: <code>"attributes": [],</code> and I want to exclude those kind of empty JSON arrays from my result. My current ObjectMapper config:</p>
  
  <pre><code>SerializationConfig config = objectMapper.getSerializationConfig();
  config.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
  config.set(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
  </code></pre>
  
  <p>From <a href="https://stackoverflow.com/questions/8899115/how-to-not-send-an-empty-collection-in-jackson">this post</a> I've read that I can use: </p>
  
  <pre><code>config.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT);
  </code></pre>
  
  <p>But that is generating me an error:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Class com.mycomp.assessments.evaluation.EvaluationImpl$1 has no default constructor; can not instantiate default bean value to support 'properties=JsonSerialize.Inclusion.NON_DEFAULT' annotation.
  </code></pre>
  
  <p>So how should I prevent those empty arrays to appear in my result?</p>