title: Using Jackson JSON Generator, how can I write multiple objects to one field?
body: <p>Suppose I have the following three classes (getters and setters left out for brevity):</p>
  
  <pre><code>@JsonAutoDetect
  public class InfoCollection{
      private InfoType1 info1;
      private InfoType2 info2;
  }
  
  @JsonAutoDetect
  public class InfoType1{
      private String fieldA;
  }
  
  @JsonAutoDetect
  public class InfoType2{
      private String fieldB;
  }
  </code></pre>
  
  <p>I"m trying to write a <code>JsonSerializer.serialize()</code> function that serializes an <code>InfoCollection</code> object in this format:</p>
  
  <pre><code>{
      "allInfo":{
          "fieldA":"foo",
          "fieldB":"bar"
      }
  }
  </code></pre>
  
  <p>This is what I have now:</p>
  
  <pre><code>jsonGenerator.writeStartObject();
  jsonGenerator.writeFieldName("allInfo");
  jsonGenerator.writeObject(myInfoCollection.getInfo1());
  jsonGenerator.writeObject(myInfoCollection.getInfo2());
  jsonGenerator.writeEndObject();
  </code></pre>
  
  <p>which is causing the following exception:</p>
  
  <pre><code> org.codehaus.jackson.JsonGenerationException: Can not start an object, expecting field name
  </code></pre>
  
  <p>Am I missing something small or am I totally going about this the wrong way?</p>
  
  <p><strong>NOTE:</strong> A couple of the proposed solutions so far involve writing each individual field of <code>InfoType1</code> and <code>InfoType2</code>.  I am looking for a solution that does not require this because I'd like to use the solution on huge classes with many fields.</p>