Skip to content

Commit b744bf3

Browse files
committed
Add failing test for #1868, related
1 parent 615bf02 commit b744bf3

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public ValueInstantiator findValueInstantiator(DeserializationContext ctxt,
267267
}
268268
}
269269

270-
// Sanity check: does the chosen instantatior have incomplete creators?
270+
// Sanity check: does the chosen ValueInstantiator have incomplete creators?
271271
if (instantiator.getIncompleteParameter() != null) {
272272
final AnnotatedParameter nonAnnotatedParam = instantiator.getIncompleteParameter();
273273
final AnnotatedWithParams ctor = nonAnnotatedParam.getOwner();
@@ -281,7 +281,8 @@ private ValueInstantiator _findStdValueInstantiator(DeserializationConfig config
281281
BeanDescription beanDesc)
282282
throws JsonMappingException
283283
{
284-
if (beanDesc.getBeanClass() == JsonLocation.class) {
284+
Class<?> raw = beanDesc.getBeanClass();
285+
if (raw == JsonLocation.class) {
285286
return new JsonLocationInstantiator();
286287
}
287288
return null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
6+
import com.fasterxml.jackson.databind.BaseMapTest;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
// Unit tests for [databind#1868], related
10+
public class TestDefaultForUtilCollections1868 extends BaseMapTest
11+
{
12+
private final ObjectMapper DEFAULT_MAPPER = new ObjectMapper();
13+
{
14+
DEFAULT_MAPPER.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
15+
}
16+
17+
/*
18+
/**********************************************************
19+
/* Unit tests, "empty" types
20+
/**********************************************************
21+
*/
22+
23+
public void testEmptyList() throws Exception {
24+
_verifyCollection(Collections.emptyList());
25+
}
26+
27+
public void testEmptySet() throws Exception {
28+
_verifyCollection(Collections.emptySet());
29+
}
30+
31+
public void testEmptyMap() throws Exception {
32+
_verifyMap(Collections.emptyMap());
33+
}
34+
35+
/*
36+
/**********************************************************
37+
/* Unit tests, "singleton" types
38+
/**********************************************************
39+
*/
40+
41+
public void testSingletonList() throws Exception {
42+
_verifyCollection(Collections.singletonList(Arrays.asList("TheOne")));
43+
}
44+
45+
public void testSingletonSet() throws Exception {
46+
_verifyCollection(Collections.singleton(Arrays.asList("TheOne")));
47+
}
48+
49+
public void testSingletonMap() throws Exception {
50+
_verifyMap(Collections.singletonMap("foo", "bar"));
51+
}
52+
53+
/*
54+
/**********************************************************
55+
/* Unit tests, "unmodifiable" types
56+
/**********************************************************
57+
*/
58+
59+
public void testUnmodifiableList() throws Exception {
60+
_verifyCollection(Collections.unmodifiableList(Arrays.asList("first", "second")));
61+
}
62+
63+
public void testUnmodifiableSet() throws Exception
64+
{
65+
Set<String> input = new LinkedHashSet<>(Arrays.asList("first", "second"));
66+
_verifyCollection(Collections.unmodifiableSet(input));
67+
}
68+
69+
public void testUnmodifiableMap() throws Exception
70+
{
71+
Map<String,String> input = new LinkedHashMap<>();
72+
input.put("a", "b");
73+
input.put("c", "d");
74+
_verifyMap(Collections.unmodifiableMap(input));
75+
}
76+
77+
/*
78+
/**********************************************************
79+
/* Helper methods
80+
/**********************************************************
81+
*/
82+
83+
protected void _verifyCollection(Collection<?> exp) throws Exception
84+
{
85+
String json = DEFAULT_MAPPER.writeValueAsString(exp);
86+
Collection<?> act = DEFAULT_MAPPER.readValue(json, Collection.class);
87+
88+
assertEquals(exp, act);
89+
assertEquals(exp.getClass(), act.getClass());
90+
}
91+
92+
protected void _verifyMap(Map<?,?> exp) throws Exception
93+
{
94+
String json = DEFAULT_MAPPER.writeValueAsString(exp);
95+
Map<?,?> act = DEFAULT_MAPPER.readValue(json, Map.class);
96+
97+
assertEquals(exp, act);
98+
assertEquals(exp.getClass(), act.getClass());
99+
}
100+
}

0 commit comments

Comments
 (0)