Skip to content

Commit 4e7cd9a

Browse files
committed
Fix #3220
1 parent 8d68957 commit 4e7cd9a

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

release-notes/CREDITS-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,9 @@ Marcos Passos (marcospassos@github(
974974
(2.10.0)
975975
* Reported #2795: Cannot detect creator arguments of mixins for JDK types
976976
(2.11.3)
977+
* Reported #3220: (regression) Factory method generic type resolution does not use
978+
Class-bound type parameter
979+
(2.12.5)
977980

978981
David Becker (dsbecker@github)
979982
* Suggested #2433: Improve `NullNode.equals()`

release-notes/VERSION-2.x

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.12.5 (not yet released)
8+
9+
#3220: (regression) Factory method generic type resolution does not use
10+
Class-bound type parameter
11+
(reported by Marcos P)
12+
713
2.12.4 (06-Jul-2021)
814

915
#3139: Deserialization of "empty" subtype with DEDUCTION failed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,14 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
219219
// 27-Oct-2020, tatu: SIGH. As per [databind#2894] there is widespread use of
220220
// incorrect bindings in the wild -- not supported (no tests) but used
221221
// nonetheless. So, for 2.11.x, put back "Bad Bindings"...
222-
// final TypeResolutionContext typeResCtxt = _typeContext;
222+
//
223223

224224
// 03-Nov-2020, ckozak: Implement generic JsonCreator TypeVariable handling [databind#2895]
225-
final TypeResolutionContext emptyTypeResCtxt = new TypeResolutionContext.Empty(typeFactory);
225+
// final TypeResolutionContext emptyTypeResCtxt = new TypeResolutionContext.Empty(typeFactory);
226+
227+
// 23-Aug-2021, tatu: Double-d'oh! As per [databind#3220], we must revert to
228+
// the Incorrect Illogical But Used By Users Bindings... for 2.x at least.
229+
final TypeResolutionContext initialTypeResCtxt = _typeContext;
226230

227231
int factoryCount = candidates.size();
228232
List<AnnotatedMethod> result = new ArrayList<>(factoryCount);
@@ -247,7 +251,7 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
247251
if (key.equals(methodKeys[i])) {
248252
result.set(i,
249253
constructFactoryCreator(candidates.get(i),
250-
emptyTypeResCtxt, mixinFactory));
254+
initialTypeResCtxt, mixinFactory));
251255
break;
252256
}
253257
}
@@ -261,8 +265,9 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
261265
// 06-Nov-2020, tatu: Fix from [databind#2895] will try to resolve
262266
// nominal static method type bindings into expected target type
263267
// (if generic types involved)
268+
// 23-Aug-2021, tatu: ... is this still needed, wrt un-fix in [databind#3220]?
264269
TypeResolutionContext typeResCtxt = MethodGenericTypeResolver.narrowMethodTypeParameters(
265-
candidate, type, typeFactory, emptyTypeResCtxt);
270+
candidate, type, typeFactory, initialTypeResCtxt);
266271
result.set(i,
267272
constructFactoryCreator(candidate, typeResCtxt, null));
268273
}

src/test/java/com/fasterxml/jackson/failing/MixinForFactoryMethod3220Test.java renamed to src/test/java/com/fasterxml/jackson/databind/mixins/MixinForFactoryMethod3220Test.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.mixins;
22

33
import java.util.Objects;
44

@@ -8,6 +8,17 @@
88
import com.fasterxml.jackson.databind.ObjectMapper;
99
import com.fasterxml.jackson.databind.json.JsonMapper;
1010

11+
// 23-Aug-2021, tatu: UGGGGH. This is a recurring problem; users assuming
12+
// that a generic type parameter T (or whatever) of a Class will be related
13+
// to locally declared type parameter with same name (T), assume Creator
14+
// factory method will magically work. Despite Java Language quite clearly
15+
// considering these separate bindings regardless of name overlap.
16+
//
17+
// But for Jackson 2.x there is common enough usage of this anti-patterns so
18+
// we cannot block it.
19+
//
20+
// NOTE! Problem is actually not the mixin handling but type resolution;
21+
// see f.ex [databind#2821], [databind#2895]
1122
public class MixinForFactoryMethod3220Test
1223
extends BaseMapTest
1324
{
@@ -125,7 +136,7 @@ public int hashCode() {
125136
}
126137

127138
// [databind#3220]
128-
public void testMixin() throws Exception
139+
public void testMixin3220() throws Exception
129140
{
130141
ObjectMapper mapper = JsonMapper.builder()
131142
.addMixIn(Timestamped.class, TimestampedMixin.class)

0 commit comments

Comments
 (0)