Skip to content

Commit 8da9a1a

Browse files
committed
add another test for #1421
1 parent 712df4d commit 8da9a1a

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

src/test/java/com/fasterxml/jackson/databind/module/TestKeyDeserializers.java

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ static class Foo {
2525

2626
public Foo(String v) { value = v; }
2727
}
28-
2928

3029
/*
3130
/**********************************************************
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package com.fasterxml.jackson.failing;
22

3-
import com.fasterxml.jackson.annotation.JsonCreator;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.fasterxml.jackson.databind.DeserializationFeature;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
7-
import org.junit.Test;
8-
93
import java.io.IOException;
4+
import java.util.ArrayList;
105
import java.util.Collections;
116
import java.util.List;
127

13-
public class SingleValueAsArray1421Test
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
11+
import com.fasterxml.jackson.core.type.TypeReference;
12+
13+
import com.fasterxml.jackson.databind.*;
14+
15+
public class SingleValueAsArray1421Test extends BaseMapTest
1416
{
1517
private static final String JSON = "[{\"message\":\"messageHere\"}]";
1618

17-
static class A
19+
static class Bean1421A
1820
{
1921
List<Messages> bs = Collections.emptyList();
2022

2123
@JsonCreator
22-
A(final List<Messages> bs)
24+
Bean1421A(final List<Messages> bs)
2325
{
2426
this.bs = bs;
2527
}
@@ -36,7 +38,7 @@ static class Messages
3638
}
3739
}
3840

39-
public static class MessageWrapper
41+
static class MessageWrapper
4042
{
4143
String message;
4244

@@ -47,11 +49,38 @@ public static class MessageWrapper
4749
}
4850
}
4951

50-
@Test
52+
static class Bean1421B<T> {
53+
T value;
54+
55+
@JsonCreator
56+
public Bean1421B(T value) {
57+
this.value = value;
58+
}
59+
}
60+
61+
/*
62+
/**********************************************************
63+
/* Unit tests
64+
/**********************************************************
65+
*/
66+
67+
private final ObjectMapper MAPPER = new ObjectMapper();
68+
{
69+
MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
70+
}
71+
5172
public void testSuccessfulDeserializationOfObjectWithChainedArrayCreators() throws IOException
5273
{
53-
ObjectMapper om = new ObjectMapper();
54-
om.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
55-
om.readValue(JSON, A.class);
74+
MAPPER.readValue(JSON, Bean1421A.class);
75+
}
76+
77+
public void test2() throws Exception {
78+
ObjectMapper objectMapper = new ObjectMapper();
79+
objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
80+
Bean1421B<List<String>> a = objectMapper.readValue(quote("test2"),
81+
new TypeReference<Bean1421B<List<String>>>() {});
82+
List<String> expected = new ArrayList<>();
83+
expected.add("test2");
84+
assertEquals(expected, a.value);
5685
}
5786
}

0 commit comments

Comments
 (0)