I have very simple Jackson code to deserialize a nested JSON object:
public class MapTest
{
public static void main(String ... args) throws Exception
{
final String ser = "{\"nested\":{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}}";
final Map<String, Object> deser = new ObjectMapper().readValue(ser, new TypeReference<TreeMap<String, Object>>(){});
System.out.println("Class of deser nested object is " + deser.get("nested").getClass().getSimpleName());
}
}
When I run this, I get the following output:
Class of deser nested object is LinkedHashMap
However, I want the embedded card to be deserialized as TreeMap, rather than as LinkedHashMapper output. How can I tell Jackson to use default TreeMapwhen deserializing?
After reading the documentation, the closest thing I discovered is the ability to define specific classes for abstract types through addAbstractTypeMapping()in a module, but I tried every superclass and instance LinkedHashMapin an attempt to do this and nothing seems to work.
This uses Jackson 2.4.2, although if there is a way to do this that requires a higher version, I could upgrade.