fixed #234
diff --git a/release-notes/VERSION b/release-notes/VERSION
index 8e036b8..b678315 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -3,6 +3,8 @@
One more patch release for 1.9...
+[Issue#234]: Problems serializing types for deeply nested Maps.
+
------------------------------------------------------------------------
=== History: ===
------------------------------------------------------------------------
diff --git a/src/mapper/java/org/codehaus/jackson/map/ser/std/MapSerializer.java b/src/mapper/java/org/codehaus/jackson/map/ser/std/MapSerializer.java
index c2c447c..041da2f 100644
--- a/src/mapper/java/org/codehaus/jackson/map/ser/std/MapSerializer.java
+++ b/src/mapper/java/org/codehaus/jackson/map/ser/std/MapSerializer.java
@@ -344,7 +344,11 @@
if (cc == prevValueClass) {
currSerializer = prevValueSerializer;
} else {
- currSerializer = provider.findValueSerializer(cc, _property);
+ if (_valueType.hasGenericTypes()) {
+ currSerializer = provider.findValueSerializer(provider.constructSpecializedType(_valueType, cc), _property);
+ } else {
+ currSerializer = provider.findValueSerializer(cc, _property);
+ }
prevValueSerializer = currSerializer;
prevValueClass = cc;
}
@@ -417,6 +421,5 @@
}
return result.serializer;
}
-
}
diff --git a/src/test/org/codehaus/jackson/map/jsontype/TestDefaultForMaps.java b/src/test/org/codehaus/jackson/map/jsontype/TestDefaultForMaps.java
index 15be85e..97741a3 100644
--- a/src/test/org/codehaus/jackson/map/jsontype/TestDefaultForMaps.java
+++ b/src/test/org/codehaus/jackson/map/jsontype/TestDefaultForMaps.java
@@ -39,6 +39,33 @@
public Map<MapKey,List<Object>> map;
}
+ // // For #234
+
+ static class ItemList {
+ public String value;
+ public List<ItemList> childItems = new LinkedList<ItemList>();
+
+ public void addChildItem(ItemList l) { childItems.add(l); }
+ }
+
+ static class ItemMap
+ {
+ public String value;
+
+ public Map<String, List<ItemMap>> childItems = new HashMap<String, List<ItemMap>>();
+
+ public void addChildItem(String key, ItemMap childItem) {
+ List<ItemMap> items;
+ if (childItems.containsKey(key)) {
+ items = childItems.get(key);
+ } else {
+ items = new ArrayList<ItemMap>();
+ }
+ items.add(childItem);
+ childItems.put(key, items);
+ }
+ }
+
/*
/**********************************************************
/* Unit tests
@@ -94,4 +121,38 @@
return TypeNameIdResolver.construct(mapper.getDeserializationConfig(),
TypeFactory.defaultInstance().constructType(Object.class), subtypes, forSerialization, !forSerialization);
}
+
+ // // For #234:
+
+ public void testList() throws Exception
+ {
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, JsonTypeInfo.As.PROPERTY);
+ ItemList child = new ItemList();
+ child.value = "I am child";
+
+ ItemList parent = new ItemList();
+ parent.value = "I am parent";
+ parent.addChildItem(child);
+ String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(parent);
+
+ Object o = mapper.readValue(json, ItemList.class);
+ assertNotNull(o);
+ }
+
+ public void testMap() throws Exception
+ {
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, JsonTypeInfo.As.PROPERTY);
+ ItemMap child = new ItemMap();
+ child.value = "I am child";
+
+ ItemMap parent = new ItemMap();
+ parent.value = "I am parent";
+ parent.addChildItem("child", child);
+
+ String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(parent);
+ Object o = mapper.readValue(json, ItemMap.class);
+ assertNotNull(o);
+ }
}