Skip to content

Commit 094f7b4

Browse files
authored
Fix #4309 (#4320)
1 parent 7942393 commit 094f7b4

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

release-notes/VERSION-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Project: jackson-databind
3131
#4262: Improve handling of `null` insertion failure for `TreeSet`
3232
#4263: Change `ObjectArrayDeserializer` to use "generic" type parameter
3333
(`java.lang.Object`) to remove co-variant return type
34+
#4309: `@JsonSetter(nulls=...)` handling of `Collection` `null` values during
35+
deserialization with `READ_UNKNOWN_ENUM_VALUES_AS_NULL` and `FAIL_ON_INVALID_SUBTYPE` wrong
36+
(reported by @ivan-zaitsev)
37+
(fix contributed by Joo-Hyuk K)
3438

3539
2.16.2 (not yet released)
3640

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,15 @@ protected final Collection<Object> handleNonArray(JsonParser p, DeserializationC
413413
return result;
414414
}
415415
value = _nullProvider.getNullValue(ctxt);
416-
if (value == null) {
417-
_tryToAddNull(p, ctxt, result);
418-
return result;
419-
}
420416
} else if (typeDeser == null) {
421417
value = valueDes.deserialize(p, ctxt);
422418
} else {
423419
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
424420
}
421+
if (value == null) {
422+
_tryToAddNull(p, ctxt, result);
423+
return result;
424+
}
425425
} catch (Exception e) {
426426
boolean wrap = ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
427427
if (!wrap) {
@@ -464,6 +464,9 @@ protected Collection<Object> _deserializeWithObjectId(JsonParser p, Deserializat
464464
} else {
465465
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
466466
}
467+
if (value == null && _skipNullValues) {
468+
continue;
469+
}
467470
referringAccumulator.add(value);
468471
} catch (UnresolvedForwardReference reference) {
469472
Referring ref = referringAccumulator.handleUnresolvedReference(reference);
@@ -480,14 +483,18 @@ protected Collection<Object> _deserializeWithObjectId(JsonParser p, Deserializat
480483
}
481484

482485
/**
483-
* {@code java.util.TreeSet} does not allow addition of {@code null} values,
484-
* so isolate handling here.
486+
* {@code java.util.TreeSet} (and possibly other {@link Collection} types) does not
487+
* allow addition of {@code null} values, so isolate handling here.
485488
*
486489
* @since 2.17
487490
*/
488491
protected void _tryToAddNull(JsonParser p, DeserializationContext ctxt, Collection<?> set)
489492
throws IOException
490493
{
494+
if (_skipNullValues) {
495+
return;
496+
}
497+
491498
// Ideally we'd have better idea of where nulls are accepted, but first
492499
// let's just produce something better than NPE:
493500
try {

src/test/java/com/fasterxml/jackson/failing/NullsSkip4309Test.java src/test/java/com/fasterxml/jackson/databind/deser/NullsSkip4309Test.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.deser;
22

33
import java.util.List;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.JsonSetter;
68
import com.fasterxml.jackson.annotation.JsonSubTypes;
79
import com.fasterxml.jackson.annotation.JsonTypeInfo;
810
import com.fasterxml.jackson.annotation.Nulls;
9-
import org.junit.jupiter.api.Test;
10-
1111
import com.fasterxml.jackson.core.type.TypeReference;
1212
import com.fasterxml.jackson.databind.DeserializationFeature;
1313
import com.fasterxml.jackson.databind.json.JsonMapper;

0 commit comments

Comments
 (0)