9
9
10
10
import com .fasterxml .jackson .databind .*;
11
11
12
+ import java .util .Date ;
13
+
12
14
public class ArrayMergeTest extends BaseMapTest
13
15
{
14
16
static class MergedX <T >
@@ -19,7 +21,13 @@ static class MergedX<T>
19
21
public MergedX (T v ) { value = v ; }
20
22
protected MergedX () { }
21
23
}
22
-
24
+
25
+ static class Merged
26
+ {
27
+ @ JsonMerge (OptBoolean .TRUE )
28
+ public Date [] value ;
29
+ }
30
+
23
31
/*
24
32
/********************************************************
25
33
/* Test methods
@@ -57,6 +65,31 @@ public void testObjectArrayMerging() throws Exception
57
65
assertEquals ("zap" , result .value [2 ]);
58
66
}
59
67
68
+ public void testComponentTypeArrayMerging () throws Exception
69
+ {
70
+ Merged input = new Merged ();
71
+ input .value = new Date [] {new Date (1000L )};
72
+ final JavaType type = MAPPER .getTypeFactory ().constructType (new TypeReference <Merged >() {});
73
+ Merged result = MAPPER .readerFor (type )
74
+ .withValueToUpdate (input )
75
+ .readValue (a2q ("{'value':[2000]}" ));
76
+ assertSame (input , result );
77
+ assertEquals (2 , result .value .length );
78
+ assertEquals (1000L , result .value [0 ].getTime ());
79
+ assertEquals (2000L , result .value [1 ].getTime ());
80
+
81
+ // and with one trick
82
+ result = MAPPER .readerFor (type )
83
+ .with (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY )
84
+ .withValueToUpdate (input )
85
+ .readValue (a2q ("{'value':3000}" ));
86
+ assertSame (input , result );
87
+ assertEquals (3 , result .value .length );
88
+ assertEquals (1000L , result .value [0 ].getTime ());
89
+ assertEquals (2000L , result .value [1 ].getTime ());
90
+ assertEquals (3000L , result .value [2 ].getTime ());
91
+ }
92
+
60
93
public void testStringArrayMerging () throws Exception
61
94
{
62
95
MergedX <String []> input = new MergedX <String []>(new String [] { "foo" });
0 commit comments