title: Jackson serialization key and value from one object
body: <p>I am trying to create a custom serializer to generate Pair object but I want to avoid "key" and "value" fields when the object is serialized. </p>
  
  <p>Object pojo:</p>
  
  <pre><code>public class TypeObjectPair implements Serializable {
  
  
      private final String canonicalObjectName;
      private final Object object;
  
  
      public String getKey() {
          return canonicalObjectName;
      }
  
      public Object getValue() {
          return object;
      }
  
  
  }
  </code></pre>
  
  <p>Person class. (Theoretically could be any other object class) </p>
  
  <pre><code>class Person{
      int id;
      String name;
  }
  </code></pre>
  
  <p>Final object to serialize:</p>
  
  <pre><code>TypeObjectPair obj = new TypeObjectPair("com.example.Person", new Person(1, "Peter"));
  </code></pre>
  
  <p>Required output: </p>
  
  <pre><code>{
      "com.example.object" : {
                                "id" : 1,
                                "name" : "Peter"    
                             }
  }
  </code></pre>
  
  <p>Any ideas on how to achieve it? </p>