Skip to content

Commit 97f741b

Browse files
committed
Update release notes wrt #2895
1 parent b619003 commit 97f741b

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

release-notes/CREDITS-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ Jakub Skierbiszewski (jskierbi@github)
808808
Carter Kozak (cakofony@github)
809809
* Reported #2016: Delegating JsonCreator disregards JsonDeserialize info
810810
(2.9.6)
811+
* Contributed #2895: Improve static factory method generic type resolution logic
812+
(as well as better test coverage)
813+
(2.12.0)
811814
812815
Reinhard Prechtl (dnno@github)
813816
* Reported #2034: Serialization problem with type specialization of nested generic types

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Project: jackson-databind
2626
#2885: Add `JsonNode.canConvertToExactIntegral()` to indicate whether floating-point/BigDecimal
2727
values could be converted to integers losslessly
2828
(requested by Oguzhan U; implementation contributed by Siavash S)
29+
#2895: Improve static factory method generic type resolution logic
30+
(contributed by Carter K)
2931
#2903: Allow preventing "Enum from integer" coercion using new `CoercionConfig` system
3032
#2909: `@JsonValue` not considered when evaluating inclusion
3133
(reported by chrylis@github)

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedCreatorCollector.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,13 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
258258
AnnotatedMethod factory = result.get(i);
259259
if (factory == null) {
260260
Method candidate = candidates.get(i);
261-
// Apply generic type information based on the requested type
261+
// 06-Nov-2020, tatu: Fix from [databind#2895] will try to resolve
262+
// nominal static method type bindings into expected target type
263+
// (if generic types involved)
262264
TypeResolutionContext typeResCtxt = MethodGenericTypeResolver.narrowMethodTypeParameters(
263265
candidate, type, typeFactory, emptyTypeResCtxt);
264266
result.set(i,
265-
constructFactoryCreator(candidate,
266-
typeResCtxt, null));
267+
constructFactoryCreator(candidate, typeResCtxt, null));
267268
}
268269
}
269270
return result;

src/main/java/com/fasterxml/jackson/databind/introspect/MethodGenericTypeResolver.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
import java.util.Objects;
1414

1515
/**
16-
* Internal utility functionality to handle type resolution for method type variables based on the requested
17-
* result type.
16+
* Internal utility functionality to handle type resolution for method type variables
17+
* based on the requested result type: this is needed to work around the problem of
18+
* static factory methods not being able to use class type variable bindings
19+
* (see [databind#2895] for more).
20+
*
21+
* @since 2.12
1822
*/
19-
final class MethodGenericTypeResolver {
20-
23+
final class MethodGenericTypeResolver
24+
{
2125
/*
2226
* Attempt to narrow types on a generic factory method based on the expected result (requestedType).
2327
* If narrowing was possible, a new TypeResolutionContext is returned with the discovered TypeBindings,
@@ -30,7 +34,7 @@ final class MethodGenericTypeResolver {
3034
* as though the method was written with defined types:
3135
* @JsonCreator static Wrapper<Duck> fromJson(Duck value)
3236
*/
33-
static TypeResolutionContext narrowMethodTypeParameters(
37+
public static TypeResolutionContext narrowMethodTypeParameters(
3438
Method candidate,
3539
JavaType requestedType,
3640
TypeFactory typeFactory,
@@ -214,8 +218,4 @@ private static TypeVariable<?> findByName(TypeVariable<?>[] typeVariables, Strin
214218
}
215219
return null;
216220
}
217-
218-
private MethodGenericTypeResolver() {
219-
// Utility class
220-
}
221221
}

0 commit comments

Comments
 (0)