title: Jackson: Deserialize to a Map<String, Object> with correct type for each value
body: <p>I have a class that looks like the following</p>
  
  <pre><code>public class MyClass {
     private String val1;
     private String val2;
     private Map&lt;String,Object&gt; context;
     // Appropriate accessors removed for brevity.
     ...
  }
  </code></pre>
  
  <p>I'm looking to be able to make the round trip with Jackson from object to JSON and back.  I can serialize the object above fine and receive the following output:</p>
  
  <pre><code>{
      "val1": "foo",
      "val2": "bar",
      "context": {
          "key1": "enumValue1",
          "key2": "stringValue1",
          "key3": 3.0
      }
  }
  </code></pre>
  
  <p>The issue I'm running into is that since the values in the serialized map do not have any type information, they are not deserialized correctly.  For example, in the sample above, enumValue1 should be deserialized as an enum value but is instead deserialized as a String.  I've seen examples for basing what type on a variety of things, but in my scenario, I won't know what the types are (they will be user generated objects that I won't know in advance) so I need to be able to serialize the type information with the key value pair.  How can I accomplish this with Jackson?</p>
  
  <p>For the record, I'm using Jackson version 2.4.2.  The code I'm using to test the round trip is as follows:</p>
  
  <pre><code>@Test
  @SuppressWarnings("unchecked")
  public void testJsonSerialization() throws Exception {
      // Get test object to serialize
      T serializationValue = getSerializationValue();
      // Serialize test object
      String json = mapper.writeValueAsString(serializationValue);
      // Test that object was serialized as expected
      assertJson(json);
      // Deserialize to complete round trip
      T roundTrip = (T) mapper.readValue(json, serializationValue.getClass());
      // Validate that the deserialized object matches the original one
      assertObject(roundTrip);
  }
  </code></pre>
  
  <p>Since this is a Spring based project, the mapper is being created as follows:</p>
  
  <pre><code>@Configuration
  public static class SerializationConfiguration {
  
      @Bean
      public ObjectMapper mapper() {
          Map&lt;Class&lt;?&gt;, Class&lt;?&gt;&gt; mixins = new HashMap&lt;Class&lt;?&gt;, Class&lt;?&gt;&gt;();
          // Add unrelated MixIns
          .. 
  
          return new Jackson2ObjectMapperBuilder()
                  .featuresToDisable(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)
                  .dateFormat(new ISO8601DateFormatWithMilliSeconds())
                  .mixIns(mixins)
                  .build();
      }
  }
  </code></pre>