title: How should I convert an objects attribute of type list containing one object to an attribute of type object using Jackson?
body: <p>I have a POJO like the following:</p>
  <pre><code>public class Foo {
     private String name;
     private List&lt;Bar&gt; bars;
     // getters and setters
  }
  </code></pre>
  <p>It is possible that <code>bars</code> could be a null reference, a list containing 0 elements, a list containing 1 element, or a list containing more than 1 element.</p>
  <p>The serialization of this object will look like this when converted to JSON:</p>
  <pre><code>{
     &quot;name: &quot;foo&quot;,
     &quot;bars: [{}, {}]
  }
  </code></pre>
  <p>In the case that the list contains 1 element, I have a requirement that the <em>type</em> of <code>bars</code> be &quot;condensed&quot; to a single object upon serialization. The JSON representation should look something like this:</p>
  <pre><code>{
     &quot;name&quot;: &quot;foo&quot;,
     &quot;bars&quot;: {}
  }
  </code></pre>
  <p>How can I achieve this using Jackson?</p>