-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests to drill down to #234
- Loading branch information
1 parent
9142441
commit c77814e
Showing
2 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/test/java/com/fasterxml/jackson/failing/TestIssue234.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |