Skip to content

Commit 50be366

Browse files
committed
Merge branch '2.14' into 2.15
2 parents dc19ee8 + e5f02ff commit 50be366

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,10 @@ Gili Tzabari (cowwoc@github)
15441544
* Reported #3063: `@JsonValue` fails for Java Record
15451545
(2.14.2)
15461546
1547+
Yury Molchan (yurkom@github)
1548+
* Contributed #4121: Preserve the original component type in merging to an array
1549+
(2.14.4)
1550+
15471551
Joo Hyuk Kim (JooHyukKim@github)
15481552
* Contributed #2536: Add `EnumFeature.READ_ENUM_KEYS_USING_INDEX` to work with
15491553
existing "WRITE_ENUM_KEYS_USING_INDEX"
@@ -1638,5 +1642,3 @@ Antti Lampinen (arlampin@github)
16381642
* Reported #3897: 2.15.0 breaks deserialization when POJO/Record only has a single field
16391643
and is marked `Access.WRITE_ONLY`
16401644
(2.15.1)
1641-
1642-

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Project: jackson-databind
88

99
#3968: Records with additional constructors failed to deserialize
1010
(fix contributed by Sim Y-T)
11+
#4121: Preserve the original component type in merging to an array
12+
(contributed by Yury M)
1113

1214
2.15.2 (30-May-2023)
1315

src/main/java/com/fasterxml/jackson/databind/deser/std/ObjectArrayDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.lang.reflect.Array;
5+
import java.util.Arrays;
56
import java.util.Objects;
67

78
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -258,8 +259,7 @@ public Object[] deserialize(JsonParser p, DeserializationContext ctxt,
258259
return intoValue;
259260
}
260261
final int offset = intoValue.length;
261-
Object[] result = new Object[offset + arr.length];
262-
System.arraycopy(intoValue, 0, result, 0, offset);
262+
Object[] result = Arrays.copyOf(intoValue, offset + arr.length);
263263
System.arraycopy(arr, 0, result, offset, arr.length);
264264
return result;
265265
}

src/test/java/com/fasterxml/jackson/databind/deser/merge/ArrayMergeTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import com.fasterxml.jackson.databind.*;
1111

12+
import java.util.Date;
13+
1214
public class ArrayMergeTest extends BaseMapTest
1315
{
1416
static class MergedX<T>
@@ -20,6 +22,13 @@ static class MergedX<T>
2022
protected MergedX() { }
2123
}
2224

25+
// [databind#4121]
26+
static class Merged4121
27+
{
28+
@JsonMerge(OptBoolean.TRUE)
29+
public Date[] value;
30+
}
31+
2332
/*
2433
/********************************************************
2534
/* Test methods
@@ -57,6 +66,31 @@ public void testObjectArrayMerging() throws Exception
5766
assertEquals("zap", result.value[2]);
5867
}
5968

69+
// [databind#4121]
70+
public void testComponentTypeArrayMerging() throws Exception
71+
{
72+
Merged4121 input = new Merged4121();
73+
input.value = new Date[] {new Date(1000L)};
74+
Merged4121 result = MAPPER.readerFor(Merged4121.class)
75+
.withValueToUpdate(input)
76+
.readValue(a2q("{'value':[2000]}"));
77+
assertSame(input, result);
78+
assertEquals(2, result.value.length);
79+
assertEquals(1000L, result.value[0].getTime());
80+
assertEquals(2000L, result.value[1].getTime());
81+
82+
// and with one trick
83+
result = MAPPER.readerFor(Merged4121.class)
84+
.with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
85+
.withValueToUpdate(input)
86+
.readValue(a2q("{'value':3000}"));
87+
assertSame(input, result);
88+
assertEquals(3, result.value.length);
89+
assertEquals(1000L, result.value[0].getTime());
90+
assertEquals(2000L, result.value[1].getTime());
91+
assertEquals(3000L, result.value[2].getTime());
92+
}
93+
6094
public void testStringArrayMerging() throws Exception
6195
{
6296
MergedX<String[]> input = new MergedX<String[]>(new String[] { "foo" });

0 commit comments

Comments
 (0)