@@ -12,19 +12,35 @@ final class OptionalDeserializer
12
12
{
13
13
private static final long serialVersionUID = 1L ;
14
14
15
+ protected final boolean _cfgReadAbsentAsNull ;
16
+
15
17
/*
16
18
/**********************************************************
17
19
/* Life-cycle
18
20
/**********************************************************
19
21
*/
20
22
23
+ /**
24
+ * @since 2.14
25
+ */
26
+ public OptionalDeserializer (JavaType fullType , ValueInstantiator inst ,
27
+ TypeDeserializer typeDeser , JsonDeserializer <?> deser ,
28
+ boolean cfgReadAbsentAsNull )
29
+ {
30
+ super (fullType , inst , typeDeser , deser );
31
+ _cfgReadAbsentAsNull = cfgReadAbsentAsNull ;
32
+ }
33
+
21
34
/**
22
35
* @since 2.9
36
+ * @deprecated Since 2.14
23
37
*/
38
+ @ Deprecated // @since 2.14
24
39
public OptionalDeserializer (JavaType fullType , ValueInstantiator inst ,
25
40
TypeDeserializer typeDeser , JsonDeserializer <?> deser )
26
41
{
27
- super (fullType , inst , typeDeser , deser );
42
+ this (fullType , inst , typeDeser , deser ,
43
+ Jdk8Module .DEFAULT_READ_ABSENT_AS_NULL );
28
44
}
29
45
30
46
/*
@@ -36,7 +52,7 @@ public OptionalDeserializer(JavaType fullType, ValueInstantiator inst,
36
52
@ Override
37
53
public OptionalDeserializer withResolved (TypeDeserializer typeDeser , JsonDeserializer <?> valueDeser ) {
38
54
return new OptionalDeserializer (_fullType , _valueInstantiator ,
39
- typeDeser , valueDeser );
55
+ typeDeser , valueDeser , _cfgReadAbsentAsNull );
40
56
}
41
57
42
58
@ Override
@@ -53,6 +69,21 @@ public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingExcep
53
69
return getNullValue (ctxt );
54
70
}
55
71
72
+ /**
73
+ * As of Jackson 2.14 we will either return either same as
74
+ * {@link #getNullValue} or {@code null}: see
75
+ * {@like Jdk8Module#configureReadAbsentLikeNull(boolean)} for
76
+ * details.
77
+ */
78
+ @ Override // @since 2.14
79
+ public Object getAbsentValue (DeserializationContext ctxt ) throws JsonMappingException {
80
+ // Note: actual `null` vs "null value" (which is coerced as "empty")
81
+ if (_cfgReadAbsentAsNull ) {
82
+ return null ;
83
+ }
84
+ return getNullValue (ctxt );
85
+ }
86
+
56
87
@ Override
57
88
public Optional <?> referenceValue (Object contents ) {
58
89
return Optional .ofNullable (contents );
0 commit comments