|
5 | 5 | import java.util.Objects;
|
6 | 6 |
|
7 | 7 | import com.fasterxml.jackson.annotation.JsonFormat;
|
| 8 | + |
8 | 9 | import com.fasterxml.jackson.core.*;
|
| 10 | + |
9 | 11 | import com.fasterxml.jackson.databind.*;
|
10 | 12 | import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
|
11 | 13 | import com.fasterxml.jackson.databind.cfg.CoercionAction;
|
@@ -355,6 +357,10 @@ protected Collection<Object> _deserializeFromArray(JsonParser p, Deserialization
|
355 | 357 | continue;
|
356 | 358 | }
|
357 | 359 | value = _nullProvider.getNullValue(ctxt);
|
| 360 | + if (value == null) { |
| 361 | + _tryToAddNull(p, ctxt, result); |
| 362 | + continue; |
| 363 | + } |
358 | 364 | } else if (typeDeser == null) {
|
359 | 365 | value = valueDes.deserialize(p, ctxt);
|
360 | 366 | } else {
|
@@ -407,6 +413,10 @@ protected final Collection<Object> handleNonArray(JsonParser p, DeserializationC
|
407 | 413 | return result;
|
408 | 414 | }
|
409 | 415 | value = _nullProvider.getNullValue(ctxt);
|
| 416 | + if (value == null) { |
| 417 | + _tryToAddNull(p, ctxt, result); |
| 418 | + return result; |
| 419 | + } |
410 | 420 | } else if (typeDeser == null) {
|
411 | 421 | value = valueDes.deserialize(p, ctxt);
|
412 | 422 | } else {
|
@@ -469,6 +479,25 @@ protected Collection<Object> _deserializeWithObjectId(JsonParser p, Deserializat
|
469 | 479 | return result;
|
470 | 480 | }
|
471 | 481 |
|
| 482 | + /** |
| 483 | + * {@code java.util.TreeSet} does not allow addition of {@code null} values, |
| 484 | + * so isolate handling here. |
| 485 | + * |
| 486 | + * @since 2.17 |
| 487 | + */ |
| 488 | + protected void _tryToAddNull(JsonParser p, DeserializationContext ctxt, Collection<?> set) |
| 489 | + throws IOException |
| 490 | + { |
| 491 | + // Ideally we'd have better idea of where nulls are accepted, but first |
| 492 | + // let's just produce something better than NPE: |
| 493 | + try { |
| 494 | + set.add(null); |
| 495 | + } catch (NullPointerException e) { |
| 496 | + ctxt.handleUnexpectedToken(_valueType, JsonToken.VALUE_NULL, p, |
| 497 | + "`java.util.Collection` of type %s does not accept `null` values", |
| 498 | + ClassUtil.getTypeDescription(getValueType(ctxt))); |
| 499 | + } |
| 500 | + } |
472 | 501 | /**
|
473 | 502 | * Helper class for dealing with Object Id references for values contained in
|
474 | 503 | * collections being deserialized.
|
|
0 commit comments