title: jackson serialization for Java object with Map?
body: <p>I have a Java class like this and want to convert to JSON using Jackson. Thanks for your help.</p>
  
  <ol>
  <li><h3>Java Class</h3>
  
  <pre><code>public class myClass {
     String Id;
     Map&lt;String, Object&gt; optionalData = new LinkedHashMap&lt;String, Object&gt;();
  }
  </code></pre></li>
  <li><h3>How to serialization it to JSON using Jackson ObjectMapper ?</h3></li>
  </ol>
  
  <p>For example, suppose the <code>optionalData</code> is a Map saving two entries <code>&lt;"type", "book"&gt;</code> and <code>&lt;"year", "2014"&gt;</code>
  I want the output to be as follow. Please note that the key/value of optionalData could be changed on the fly (so, I cannot create a "static" Java object for this without using Map)</p>
  
  <pre><code>  [ 
      { 
        id: "book-id1",
        type: "book",
        year: "2014"
      },
      { 
        id: "book-id2",
        type: "book",
        year: "2013"
       }
    ]
  </code></pre>