Skip to content

Commit 36436cd

Browse files
committed
Merge branch '2.11'
2 parents f315f1b + 3d1b039 commit 36436cd

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

release-notes/CREDITS-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,8 @@ João Guerra (joca-bt@github)
984984
* Reported #2473: Array index missing in path of `JsonMappingException` for `Collection<String>`,
985985
with custom deserializer
986986
(2.10.1)
987+
* Reported #2567: Incorrect target type for arrays when providing nulls and nulls are disabled
988+
(2.10.2)
987989
988990
Ryan Bohn (bohnman@github)
989991
* Reported #2475: `StringCollectionSerializer` calls `JsonGenerator.setCurrentValue(value)`,

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Project: jackson-databind
3737
(reported by Fabian L)
3838
#2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()`
3939
(reported by Stefan W)
40+
#2567: Incorrect target type for arrays when providing nulls and nulls are disabled
41+
(reported by João G)
4042
4143
2.10.1 (09-Nov-2019)
4244

src/main/java/com/fasterxml/jackson/databind/deser/impl/NullsFailProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ protected NullsFailProvider(PropertyName name, JavaType type) {
2323
}
2424

2525
public static NullsFailProvider constructForProperty(BeanProperty prop) {
26-
return new NullsFailProvider(prop.getFullName(), prop.getType());
26+
return constructForProperty(prop, prop.getType());
27+
}
28+
29+
// @since 2.10.2
30+
public static NullsFailProvider constructForProperty(BeanProperty prop, JavaType type) {
31+
return new NullsFailProvider(prop.getFullName(), type);
2732
}
2833

2934
public static NullsFailProvider constructForRootValue(JavaType t) {

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

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
102102
nuller = NullsConstantProvider.skipper();
103103
} else if (nullStyle == Nulls.FAIL) {
104104
if (property == null) {
105-
nuller = NullsFailProvider.constructForRootValue(ctxt.constructType(_valueClass));
105+
// 09-Dec-2019, tatu: [databind#2567] need to ensure correct target type
106+
nuller = NullsFailProvider.constructForRootValue(ctxt.constructType(_valueClass.getComponentType()));
106107
} else {
107-
nuller = NullsFailProvider.constructForProperty(property);
108+
// 09-Dec-2019, tatu: [databind#2567] need to ensure correct target type
109+
nuller = NullsFailProvider.constructForProperty(property, property.getType().getContentType());
108110
}
109111
}
110112
if ((unwrapSingle == _unwrapSingle) && (nuller == _nuller)) {
@@ -190,29 +192,7 @@ public T deserialize(JsonParser p, DeserializationContext ctxt, T existing) thro
190192
/* Helper methods for sub-classes
191193
/********************************************************
192194
*/
193-
194-
/*
195-
* Convenience method that constructs a concatenation of two arrays,
196-
* with the type they have.
197-
*
198-
* @since 2.9
199-
@SuppressWarnings("unchecked")
200-
public static <T> T concatArrays(T array1, T array2)
201-
{
202-
int len1 = Array.getLength(array1);
203-
if (len1 == 0) {
204-
return array2;
205-
}
206-
int len2 = Array.getLength(array2);
207-
if (len2 == 0) {
208-
return array1;
209-
}
210-
Object result = Arrays.copyOf((Object[]) array1, len1 + len2);
211-
System.arraycopy(array2, 0, result, len1, len2);
212-
return (T) result;
213-
}
214-
*/
215-
195+
216196
@SuppressWarnings("unchecked")
217197
protected T handleNonArray(JsonParser p, DeserializationContext ctxt) throws IOException
218198
{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,20 @@ protected NullValueProvider findContentNullProvider(DeserializationContext ctxt,
10581058
if (nulls == Nulls.SKIP) {
10591059
return NullsConstantProvider.skipper();
10601060
}
1061+
// 09-Dec-2019, tatu: [databind#2567] need to ensure correct target type (element,
1062+
// not container), so inlined here before calling _findNullProvider
1063+
if (nulls == Nulls.FAIL) {
1064+
if (prop == null) {
1065+
JavaType type = ctxt.constructType(valueDeser.handledType());
1066+
// should always be container? But let's double-check just in case:
1067+
if (type.isContainerType()) {
1068+
type = type.getContentType();
1069+
}
1070+
return NullsFailProvider.constructForRootValue(type);
1071+
}
1072+
return NullsFailProvider.constructForProperty(prop, prop.getType().getContentType());
1073+
}
1074+
10611075
NullValueProvider prov = _findNullProvider(ctxt, prop, nulls, valueDeser);
10621076
if (prov != null) {
10631077
return prov;

src/test/java/com/fasterxml/jackson/databind/deser/filter/NullConversionsForContentTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void testFailOnNullFromDefaults() throws Exception
6363
fail("Should not pass");
6464
} catch (InvalidNullException e) {
6565
verifyException(e, "property \"values\"");
66+
assertEquals(String.class, e.getTargetType());
6667
}
6768

6869
// or configured for type:
@@ -75,6 +76,7 @@ public void testFailOnNullFromDefaults() throws Exception
7576
fail("Should not pass");
7677
} catch (InvalidNullException e) {
7778
verifyException(e, "property \"values\"");
79+
assertEquals(String.class, e.getTargetType());
7880
}
7981
}
8082

@@ -98,6 +100,7 @@ public void testFailOnNullWithCollections() throws Exception
98100
fail("Should not pass");
99101
} catch (InvalidNullException e) {
100102
verifyException(e, "property \"noNulls\"");
103+
assertEquals(Integer.class, e.getTargetType());
101104
}
102105

103106
// List<String>
@@ -106,6 +109,7 @@ public void testFailOnNullWithCollections() throws Exception
106109
fail("Should not pass");
107110
} catch (InvalidNullException e) {
108111
verifyException(e, "property \"noNulls\"");
112+
assertEquals(String.class, e.getTargetType());
109113
}
110114
}
111115

@@ -118,6 +122,7 @@ public void testFailOnNullWithArrays() throws Exception
118122
fail("Should not pass");
119123
} catch (InvalidNullException e) {
120124
verifyException(e, "property \"noNulls\"");
125+
assertEquals(Object.class, e.getTargetType());
121126
}
122127

123128
// String[]
@@ -126,6 +131,7 @@ public void testFailOnNullWithArrays() throws Exception
126131
fail("Should not pass");
127132
} catch (InvalidNullException e) {
128133
verifyException(e, "property \"noNulls\"");
134+
assertEquals(String.class, e.getTargetType());
129135
}
130136
}
131137

@@ -139,20 +145,23 @@ public void testFailOnNullWithPrimitiveArrays() throws Exception
139145
fail("Should not pass");
140146
} catch (InvalidNullException e) {
141147
verifyException(e, "property \"noNulls\"");
148+
assertEquals(Boolean.TYPE, e.getTargetType());
142149
}
143150
// int[]
144151
try {
145152
MAPPER.readValue(JSON, new TypeReference<NullContentFail<int[]>>() { });
146153
fail("Should not pass");
147154
} catch (InvalidNullException e) {
148155
verifyException(e, "property \"noNulls\"");
156+
assertEquals(Integer.TYPE, e.getTargetType());
149157
}
150158
// double[]
151159
try {
152160
MAPPER.readValue(JSON, new TypeReference<NullContentFail<double[]>>() { });
153161
fail("Should not pass");
154162
} catch (InvalidNullException e) {
155163
verifyException(e, "property \"noNulls\"");
164+
assertEquals(Double.TYPE, e.getTargetType());
156165
}
157166
}
158167

@@ -165,6 +174,7 @@ public void testFailOnNullWithMaps() throws Exception
165174
fail("Should not pass");
166175
} catch (InvalidNullException e) {
167176
verifyException(e, "property \"noNulls\"");
177+
assertEquals(String.class, e.getTargetType());
168178
}
169179

170180
// Then: EnumMap<Enum,String>
@@ -174,6 +184,7 @@ public void testFailOnNullWithMaps() throws Exception
174184
fail("Should not pass");
175185
} catch (InvalidNullException e) {
176186
verifyException(e, "property \"noNulls\"");
187+
assertEquals(String.class, e.getTargetType());
177188
}
178189
}
179190

0 commit comments

Comments
 (0)