title: How to exclude empty objects from Jackson ObjectMapper?
body: <p>Basically I do not want any empty JSON arrays or objects to show up in my generated JSON files. I have already configured my ObjectMapper accordingly using the following method:</p>
  
  <pre><code>objectMapper.setSerializationInclusion(Include.NON_EMPTY);
  </code></pre>
  
  <p>This works fine for arrays, collections and Strings.
  However if i have an empty object (= all properties are null or empty) it will still show up in the generated JSON like this:</p>
  
  <pre><code>"MyObject":{}
  </code></pre>
  
  <p>Here is a possible example of what I mean with an empty object:</p>
  
  <pre><code>class MyClass
  {
      String property1 = "";
      Object property2 = null;
  }
  </code></pre>
  
  <p>In this case I want the object to be excluded completely from the generated JSON file.</p>
  
  <p>Is this possible? If yes, how to I have to configure my ObjectMapper in order to get the desired behavior?</p>