99
1010import com .fasterxml .jackson .databind .*;
1111
12+ import java .util .Date ;
13+
1214public class ArrayMergeTest extends BaseMapTest
1315{
1416 static class MergedX <T >
@@ -19,7 +21,13 @@ static class MergedX<T>
1921 public MergedX (T v ) { value = v ; }
2022 protected MergedX () { }
2123 }
22-
24+
25+ static class Merged
26+ {
27+ @ JsonMerge (OptBoolean .TRUE )
28+ public Date [] value ;
29+ }
30+
2331 /*
2432 /********************************************************
2533 /* Test methods
@@ -57,6 +65,31 @@ public void testObjectArrayMerging() throws Exception
5765 assertEquals ("zap" , result .value [2 ]);
5866 }
5967
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+
6093 public void testStringArrayMerging () throws Exception
6194 {
6295 MergedX <String []> input = new MergedX <String []>(new String [] { "foo" });
0 commit comments