Skip to content

Commit 187e0bb

Browse files
committed
Fix #3601
1 parent fb24140 commit 187e0bb

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ Versions: 3.x (for earlier see VERSION-2.x)
5454
#3047: Rename `Bean[De]SerializerModifier` as `Value[De]SerializerModifier`
5555
#3536: Create new exception type `JsonNodeException` for use by `JsonNode`-related problems
5656
#3542: Rename "com.fasterxml.jackson" -> "tools.jackson"
57+
#3601: Change `Optional` deserialization from "absent" value into `null`, from "empty"
5758
- Remove `MappingJsonFactory`
5859
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)

src/main/java/tools/jackson/databind/ext/jdk8/Jdk8OptionalDeserializer.java

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public Object getEmptyValue(DeserializationContext ctxt) {
4242
return getNullValue(ctxt);
4343
}
4444

45+
/**
46+
* Let's actually NOT coerce missing Creator parameters into empty value.
47+
*/
48+
@Override
49+
public Object getAbsentValue(DeserializationContext ctxt) {
50+
// 21-Sep-2022, tatu: [databind#3601] Let's make absent become `null`,
51+
// NOT "null value" (Empty)
52+
return null;
53+
}
54+
4555
@Override
4656
public Optional<?> referenceValue(Object contents) {
4757
return Optional.ofNullable(contents);

src/test/java/tools/jackson/databind/ext/jdk8/CreatorForOptionalTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ public void testCreatorWithOptional() throws Exception
4040
a2q("{'a':'foo'}"), CreatorWithOptionalStrings.class);
4141
assertNotNull(bean);
4242
assertNotNull(bean.a);
43-
assertNotNull(bean.b);
4443
assertTrue(bean.a.isPresent());
45-
assertFalse(bean.b.isPresent());
46-
assertEquals("foo", bean.a.get());
44+
45+
// 21-Sep-2022, tatu: [databind#3601] Changed this to now become proper
46+
// `null`. Should probably also check coercion in future.
47+
48+
assertNull(bean.b);
4749
}
4850
}

0 commit comments

Comments
 (0)