Skip to content

Commit 33ac81c

Browse files
committed
Minor refactoring wrt #4149
1 parent 74c0ca1 commit 33ac81c

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/TestMixedCollections.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKCollectionsDeserTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public XBean() { }
2727
/**********************************************************************
2828
*/
2929

30-
private final static ObjectMapper MAPPER = new ObjectMapper();
30+
private final static ObjectMapper MAPPER = newJsonMapper();
3131

3232
// And then a round-trip test for singleton collections
3333
public void testSingletonCollections() throws Exception
@@ -60,15 +60,8 @@ public void testUnmodifiableSet() throws Exception
6060

6161
assertEquals("[\"java.util.Collections$UnmodifiableSet\",[\"a\"]]", json);
6262

63-
// 04-Jan-2018, tatu: Alas, no way to make this actually work well, at this point.
64-
// In theory could jiggle things back on deser, using one of two ways:
65-
//
66-
// 1) Do mapping to regular Set/List types (abstract type mapping): would work, but get rid of immutability
67-
// 2) Have actually separate deserializer OR ValueInstantiator
68-
/*
69-
Set<String> result = mapper.readValue(json, Set.class);
63+
Set<?> result = mapper.readValue(json, Set.class);
7064
assertNotNull(result);
7165
assertEquals(1, result.size());
72-
*/
7366
}
7467
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.databind.deser.jdk;
2+
3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import com.fasterxml.jackson.core.type.TypeReference;
9+
import com.fasterxml.jackson.databind.BaseMapTest;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
12+
public class NestedCollectionsTest extends BaseMapTest
13+
{
14+
private final static ObjectMapper MAPPER = newJsonMapper();
15+
16+
// Tests from [databind#4149] to show problems wrt [databind#4122]
17+
18+
public void testMapOfLists() throws Exception
19+
{
20+
List<Integer> l1 = Arrays.asList(1, 2);
21+
List<Integer> l2 = Arrays.asList(3, 4);
22+
HashMap<Object, Object> src = new HashMap<>();
23+
src.put("key1", l1);
24+
src.put("key2", l2);
25+
String json = MAPPER.writeValueAsString(src);
26+
assertEquals(src, MAPPER.readValue(json,
27+
new TypeReference<Map<?, List<?>>>() {}));
28+
}
29+
30+
public void testMapOfMaps() throws Exception
31+
{
32+
HashMap<Object, Object> src = new HashMap<>();
33+
HashMap<Object, Object> innerMap = new HashMap<>();
34+
innerMap.put("X", "Y");
35+
src.put("1", innerMap);
36+
String json = MAPPER.writeValueAsString(src);
37+
assertEquals(src, MAPPER.readValue(json, new TypeReference<Map<?, Map<?, ?>>>() {}));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)