Skip to content

Commit 6877a5c

Browse files
committed
Merge branch '2.19' into 2.x
2 parents 62e73d8 + 618ace4 commit 6877a5c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

datatypes/src/main/java/com/fasterxml/jackson/datatype/jdk8/Jdk8Deserializers.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Jdk8Deserializers() {
2626
public Jdk8Deserializers(boolean cfgReadAbsentAsNull) {
2727
_cfgReadAbsentAsNull = cfgReadAbsentAsNull;
2828
}
29-
29+
3030
@Override // since 2.7
3131
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType,
3232
DeserializationConfig config, BeanDescription beanDesc,
@@ -52,4 +52,23 @@ public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType,
5252
}
5353
return null;
5454
}
55+
56+
// @since 2.18.5 wrt [modules-java8#372]
57+
@Override
58+
public JsonDeserializer<?> findBeanDeserializer(JavaType type,
59+
DeserializationConfig config, BeanDescription beanDesc)
60+
throws JsonMappingException
61+
{
62+
// 25-Jul-2025, tatu: [modules-java8#372] - work-around for misconfigured
63+
// `TypeFactory` that does not use `Jdk8TypeModifier`
64+
if (type.hasRawClass(Optional.class)) {
65+
// Not the cleanest but has to do: create properly resolved type;
66+
// pass `null` for `contentTypeDeserializer` and `contentDeserializer`
67+
// (to be resolver contextually)
68+
JavaType refType = config.constructType(Optional.class);
69+
return new OptionalDeserializer(refType, null, null, null,
70+
_cfgReadAbsentAsNull);
71+
}
72+
return null;
73+
}
5574
}

datatypes/src/test/java/com/fasterxml/jackson/datatype/jdk8/OptionalTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,17 @@ public void testTypeResolution() throws Exception
283283
assertTrue(t2.isCollectionLikeType());
284284
}
285285

286+
// [modules-java8#372]
287+
public void testIssue372() throws Exception
288+
{
289+
JsonNode input = MAPPER.getNodeFactory().textNode("abc");
290+
//JavaType type = MAPPER.getTypeFactory().constructType(Optional.class);
291+
JavaType type = TypeFactory.defaultInstance().constructType(Optional.class);
292+
//JavaType type = MAPPER.constructType(Optional.class);
293+
Optional<?> value = MAPPER.readValue(MAPPER.treeAsTokens(input), type);
294+
assertEquals(Optional.of("abc"), value);
295+
}
296+
286297
/*
287298
/**********************************************************
288299
/* Helper methods

release-notes/VERSION-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ No changes since 2.19.0
3131
#364: Deserialization of Month in ONE_BASED_MONTHS mode fails for value "12"
3232
(reported, fix contributed by Boleslav B)
3333

34+
2.18.5 (not yet released)
35+
36+
#372: `java.util.Optional` deserialisation fails when using `TypeFactory.defaultInstance`
37+
for creating `JavaType` for `Optional<?>`
38+
(reported by @mattlocker)
39+
3440
2.18.4 (06-May-2025)
3541

3642
#291: `InstantDeserializer` fails to parse negative numeric timestamp strings

0 commit comments

Comments
 (0)