title: Jackson Default Typing for object containing a field of Map<String, Object>
body: <p>So I've been trying to get Jackson to serialize/deserialize one object I have which is essentially of the structure:</p>
  
  <pre><code>MyObject {
      String a;
      Map&lt;String, Object&gt; map;
  }
  </code></pre>
  
  <p>where <code>map</code> can hold nested maps or 'primitive' values (<code>String</code>, <code>Integer</code>, <code>Long</code>, <code>Double</code>, ...)</p>
  
  <p>Obviously, as the type information is required to correctly deserialize this I've had to tell Jackson to do this - for which I've used default typing:</p>
  
  <pre><code>return new ObjectMapper()
          .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
          .enableDefaultTyping(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, JsonTypeInfo.As.WRAPPER_ARRAY);
  </code></pre>
  
  <p>The object ends up serializing exactly how I'd like it to, adding type information only where it is necessary:</p>
  
  <pre><code>{
     "a":"SomeString",
     "map":{
        "String1":"String1",
        "Float1":[
           "java.lang.Float",
           1.0
        ],
        "Long1":[
           "java.lang.Long",
           1
        ],
        "Int1":1,
        "Double1":1.0
     }
  }
  </code></pre>
  
  <p>However, when I attempt to deserialize this JSON with Jackson, it fails with the following error:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Can not deserialize instance of &lt;my type&gt; out of START_ARRAY token
  at [Source: N/A; line: -1, column: -1] (through reference chain: &lt;my type&gt;["name"])
  at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2615)
  at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
  at com.rbsgbm.agile.mongo.dbobject.JacksonDBObjectConverter.fromDBObject(JacksonDBObjectConverter.java:39)
  at com.rbsgbm.agile.mongo.DBCursorIterator.next(DBCursorIterator.java:32)
  at com.rbsgbm.agile.repository.StorageBasedRepository$StorageBasedQuery$StorageBasedQueryIterator.next(StorageBasedRepository.java:258)
  at com.rbsgbm.agile.repository.StorageBasedRepository$StorageBasedQuery$StorageBasedQueryIterator.next(StorageBasedRepository.java:242)
  at com.rbs.agile.strategy.strategymanager.store.mongo.MongoStrategyStore.loadStrategies(MongoStrategyStore.java:81)
  </code></pre>
  
  <p>This would suggest that it is getting confused about the value in the map where Jackson decided no type information is necessary, and thus didn't wrap it in an array.</p>
  
  <p>Could somebody advise on the correct way to do this?</p>