Skip to content

Commit 90337ec

Browse files
committed
Add failing test for #2016
1 parent eafac26 commit 90337ec

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ public String findImplicitPropertyName(AnnotatedMember param) {
100100
}
101101

102102
// [databind#1853]
103-
public static class Product {
103+
public static class Product1853 {
104104
String name;
105105

106106
public Object other, errors;
107107

108108
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
109-
public Product(@JsonProperty("name") String name) {
109+
public Product1853(@JsonProperty("name") String name) {
110110
this.name = "PROP:" + name;
111111
}
112112

113113
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
114-
public static Product from(String name){
115-
return new Product(false, "DELEG:"+name);
114+
public static Product1853 from(String name){
115+
return new Product1853(false, "DELEG:"+name);
116116
}
117117

118-
private Product(boolean bogus, String name) {
118+
private Product1853(boolean bogus, String name) {
119119
this.name = name;
120120
}
121121

@@ -193,17 +193,17 @@ public void testMultiCtor421() throws Exception
193193
// [databind#1853]
194194
public void testSerialization() throws Exception {
195195
assertEquals(quote("testProduct"),
196-
MAPPER.writeValueAsString(new Product(false, "testProduct")));
196+
MAPPER.writeValueAsString(new Product1853(false, "testProduct")));
197197
}
198198

199199
public void testDeserializationFromObject() throws Exception {
200200
final String EXAMPLE_DATA = "{\"name\":\"dummy\",\"other\":{},\"errors\":{}}";
201-
assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product.class).getName());
201+
assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product1853.class).getName());
202202
}
203203

204204
public void testDeserializationFromString() throws Exception {
205205
assertEquals("DELEG:testProduct",
206-
MAPPER.readValue(quote("testProduct"), Product.class).getName());
206+
MAPPER.readValue(quote("testProduct"), Product1853.class).getName());
207207
}
208208
}
209209

src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorsDelegating.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.fasterxml.jackson.databind.deser.creators;
22

3-
import com.fasterxml.jackson.annotation.JsonCreator;
4-
5-
import java.util.Map;
3+
import java.util.*;
64

75
import com.fasterxml.jackson.annotation.JacksonInject;
6+
import com.fasterxml.jackson.annotation.JsonCreator;
87

98
import com.fasterxml.jackson.core.JsonParser;
109
import com.fasterxml.jackson.core.JsonToken;
1110

1211
import com.fasterxml.jackson.databind.*;
12+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1313
import com.fasterxml.jackson.databind.util.TokenBuffer;
1414

1515
public class TestCreatorsDelegating extends BaseMapTest
@@ -82,14 +82,28 @@ public MapBean(Map<String, Long> map) {
8282
this.map = map;
8383
}
8484
}
85-
85+
86+
// [databind#2016]
87+
static class Wrapper2016 {
88+
private final List<String> value;
89+
90+
@JsonCreator //(mode = JsonCreator.Mode.DELEGATING)
91+
public Wrapper2016(@JsonDeserialize(as = LinkedList.class) List<String> value) {
92+
this.value = value;
93+
}
94+
95+
public List<String> getValue() {
96+
return value;
97+
}
98+
}
99+
86100
/*
87101
/**********************************************************
88-
/* Unit tests
102+
/* Test methods
89103
/**********************************************************
90104
*/
91105

92-
private final ObjectMapper MAPPER = new ObjectMapper();
106+
private final ObjectMapper MAPPER = newObjectMapper();
93107

94108
public void testBooleanDelegate() throws Exception
95109
{
@@ -180,4 +194,13 @@ public void testIssue465() throws Exception
180194
bean = MAPPER.readValue(EMPTY_JSON, MapBean.class);
181195
assertEquals(0, bean.map.size());
182196
}
197+
198+
// [databind#2016]
199+
public void testCreatorWithDeserializeAs2016() throws Exception
200+
{
201+
String json = "[\"Hello, World!\"]";
202+
Wrapper2016 actual = MAPPER.readValue(json, Wrapper2016.class);
203+
assertEquals(Collections.singletonList("Hello, World!"), actual.getValue());
204+
assertEquals(LinkedList.class, actual.getValue().getClass());
205+
}
183206
}

0 commit comments

Comments
 (0)