title: Jackson : custom collection serialization to JSON
body: <p>I am trying to json-serialize a class MyRootClass with a property that is a collection of elements of a second class MyClass:</p>
  
  <pre><code>public class MyRootClass {
     private List&lt;MyInterface&gt; list = new ArrayList&lt;MyInterface&gt;();
     // getter / setter
  }
  
  public class MyClass implements MyInterface {
     private String value = "test";    
     // getter / setter
  }
  </code></pre>
  
  <p>The following code:</p>
  
  <pre><code>MyRootClass root = new MyRootClass();
  root.getList().add(new MyClass());
  ObjectMapper mapper = new ObjectMapper();
  mapper.writeValue(System.out, root);
  </code></pre>
  
  <p>Generates this JSON output:</p>
  
  <pre><code>{"list": [ {"value":"test"} ] }
  </code></pre>
  
  <p>instead of what I need, every object in the collection serialized with a name:</p>
  
  <pre><code>{"list": [ {"myclass": {"value":"test"}} ] }
  </code></pre>
  
  <p>Is there any way to achieve it using Jackson?  I thought about writing a custom serializer, but I've not found anything related to a collection of objects.</p>