add unit tests to drill down to #234
diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java
index c7ed350..cfe6a6b 100644
--- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java
+++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestTypeNames.java
@@ -68,7 +68,18 @@
input.put("ama", new Dog("Amadeus", 13));
String json = m.writeValueAsString(input);
AnimalMap output = m.readValue(json, AnimalMap.class);
- assertEquals(input, output);
+ assertNotNull(output);
+ assertEquals(AnimalMap.class, output.getClass());
+ assertEquals(input.size(), output.size());
+
+ // for some reason, straight comparison won't work...
+ for (String name : input.keySet()) {
+ Animal in = input.get(name);
+ Animal out = output.get(name);
+ if (!in.equals(out)) {
+ fail("Animal in input was ["+in+"]; output not matching: ["+out+"]");
+ }
+ }
}
}
@@ -96,6 +107,10 @@
return name.equals(((Animal) o).name);
}
+ @Override
+ public String toString() {
+ return getClass().toString() + "('"+name+"')";
+ }
}
class Dog extends Animal
@@ -131,6 +146,11 @@
public boolean equals(Object o) {
return super.equals(o) && ((Cat) o).purrs == purrs;
}
+
+ @Override
+ public String toString() {
+ return super.toString()+"(purrs: "+purrs+")";
+ }
}
/* uses default name ("MaineCoon") since there's no @JsonTypeName,
diff --git a/src/test/java/com/fasterxml/jackson/failing/TestIssue234.java b/src/test/java/com/fasterxml/jackson/failing/TestIssue234.java
new file mode 100644
index 0000000..24989c2
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/failing/TestIssue234.java
@@ -0,0 +1,82 @@
+package com.fasterxml.jackson.failing;
+
+import java.util.*;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.databind.*;
+
+public class TestIssue234 extends BaseMapTest
+{
+ 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);
+ }
+ }
+
+ /*
+ public void testList() throws Exception {
+ String json = getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(generateItemList());
+System.out.println("ItemList as JSON:\n" +json);
+ Object o = getMapper().readValue(json, ItemList.class);
+ assertNotNull(o);
+ }
+ */
+
+ public void testMap() throws Exception {
+ String json = getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(generateItemMap());
+System.out.println("ItemMap as JSON:\n"+json);
+ Object o = getMapper().readValue(json, ItemMap.class);
+ assertNotNull(o);
+ }
+ /*
+ */
+
+ static ItemList generateItemList() {
+ ItemList child = new ItemList();
+ child.value = "I am child";
+
+ ItemList parent = new ItemList();
+ parent.value = "I am parent";
+ parent.addChildItem(child);
+ return parent;
+ }
+
+ static ItemMap generateItemMap() {
+ ItemMap child = new ItemMap();
+ child.value = "I am child";
+
+ ItemMap parent = new ItemMap();
+ parent.value = "I am parent";
+ parent.addChildItem("child", child);
+ return parent;
+ }
+
+ static ObjectMapper getMapper() {
+ final ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.enableDefaultTyping(
+// ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE,
+ ObjectMapper.DefaultTyping.NON_FINAL,
+ JsonTypeInfo.As.PROPERTY);
+// JsonTypeInfo.As.WRAPPER_ARRAY);
+ return objectMapper;
+ }
+}