title: Serialize nested object json jackson
body: <p>I am using Jackson json library to convert my POJOs to json:</p>
  
  <pre><code>    public class A {
          public String name;
          public B b;
      }
  
      public class B {
          public Object representation;
          public String bar;
      }
  </code></pre>
  
  <p>I want to serialize an instance of <code>A</code> into JSON. I am going to use the <code>ObjectMapper</code> class from <strong><a href="http://jackson.codehaus.org/" rel="nofollow">Jackson</a></strong>:</p>
  
  <pre><code>objectMapperPropertiesBuilder.setSerializationFeature(SerializationFeature.WRAP_ROOT_VALUE);
  objectMapperPropertiesBuilder.setAnnotationIntrospector(new CustomAnnotionIntrospector());
  </code></pre>
  
  <p>Here annotation introspector picks root element as all these are JAXB classes with annotations like <code>@XmlRootElement</code> and <code>@XmlType</code>:</p>
  
  <p>Ex: If I set in <code>Object</code> representation:</p>
  
  <pre><code>    public class C {
          public BigInteger ste;
          public String cr;
      }
  </code></pre>
  
  <p>Using this code, my JSON would look like this:</p>
  
  <pre><code>rootA: {
    "name": "MyExample",
    "b": {
      "rep": {
        "ste": 7,
        "cr": "C1"
      },
      "bar": "something"
    }
  }
  </code></pre>
  
  <p>But I want the root element appended to my nested <code>Object</code> too. Object can be any custom POJO. </p>
  
  <p>So in this case, I would want root element of class <code>C</code> appended in my JSON conversion. So: </p>
  
  <pre><code>rootA: {
    "name": "MyExample",
    "b": {
      "rep": {
        "rootC": {
          "ste": 7,
          "cr": "C1"
        }
      },
      "bar": "something"
    }
  }
  </code></pre>
  
  <p>How can I add the root element of a nested object in JSON conversion ? All the <code>objectMapper</code> properties I specified will be applicable to <code>class A</code>. Do I have to write a custom serializer to apply some properties to nested object ?</p>