title: How to serialize a map<Integer, Custom object> with Jackson streaming API?
body: <p>Say that I've got a </p>
  
  <pre><code>        class Person {
           ArrayList&lt;MyOtherObject&gt; lstObjects;
  ...
         }
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>Map&lt;Integer, Person&gt; personMap
  </code></pre>
  
  <p>and want to serialize that map with Jackson Streaming API?</p>
  
  <pre><code>JsonGenerator g =...;
  
  g.writeArrayFieldStart("PersonMap");
  
      if (personMap != null) {
              Iterator&lt;Map.Entry&lt;Integer, Person&gt;&gt; iter = personMap.entrySet().iterator();
              while (iter.hasNext()) {
  
                  Map.Entry&lt;Integer, Person&gt; pairs = iter.next();
                  Integer key = (Integer) pairs.getKey();
                  Person person = (Person) pairs.getValue();
                  g.writeNumber(key.intValue());
  
                  person.saveToFileRaw(g); // Write the object
  
              }
          } 
          g.writeEndArray(); // PersonMap
  </code></pre>
  
  <p>and person.saveToFileRaw looks like</p>
  
  <pre><code>try {
              g.writeStartObject();
  
              g.writeObjectFieldStart("Inf");
              if (lstInfo != null) {
                  for (PersonInfo info: lstInfo)
                      info.saveToFileRaw(g); // Write another object
              } 
              g.writeEndObject();
  
              String s = PersonType.token(type);
              g.writeStringField("Tp", s);
              g.writeStringField("Add", address);
  </code></pre>
  
  <p>So the question: how to write an array/map of custom objects? g.writeStartObject() in person.saveToFileRaw throws an exception saying that it expects a value.</p>
  
  <p>Any ideas how to do this?</p>