1
1
package com .fasterxml .jackson .failing ;
2
2
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
-
9
3
import java .io .IOException ;
4
+ import java .util .ArrayList ;
10
5
import java .util .Collections ;
11
6
import java .util .List ;
12
7
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
14
16
{
15
17
private static final String JSON = "[{\" message\" :\" messageHere\" }]" ;
16
18
17
- static class A
19
+ static class Bean1421A
18
20
{
19
21
List <Messages > bs = Collections .emptyList ();
20
22
21
23
@ JsonCreator
22
- A (final List <Messages > bs )
24
+ Bean1421A (final List <Messages > bs )
23
25
{
24
26
this .bs = bs ;
25
27
}
@@ -36,7 +38,7 @@ static class Messages
36
38
}
37
39
}
38
40
39
- public static class MessageWrapper
41
+ static class MessageWrapper
40
42
{
41
43
String message ;
42
44
@@ -47,11 +49,38 @@ public static class MessageWrapper
47
49
}
48
50
}
49
51
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
+
51
72
public void testSuccessfulDeserializationOfObjectWithChainedArrayCreators () throws IOException
52
73
{
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 );
56
85
}
57
86
}
0 commit comments