Skip to content

Commit d9fbc18

Browse files
committed
Fix #2894
1 parent 004522c commit d9fbc18

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,7 @@ Nils Christian Ehmke (nils-christian@github)
11591159
Daniel Wu (DanielYWoo@github)
11601160
* Reported #2840: `ObjectMapper.activateDefaultTypingAsProperty()` is not using
11611161
(2.11.3)
1162+
1163+
Łukasz Walkiewicz (lukasz-walkiewicz@github)
1164+
* Reported #2894: Fix type resolution for static methods (regression in 2.11.3)
1165+
(2.11.4)

release-notes/VERSION-2.x

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

7+
2.11.4 (not yet released)
8+
9+
#2894: Fix type resolution for static methods (regression in 2.11.3)
10+
(reported by Łukasz W)
11+
712
2.11.3 (02-Oct-2020)
813

914
#2795: Cannot detect creator arguments of mixins for JDK types

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ private List<AnnotatedMethod> _findPotentialFactories(JavaType type, Class<?> pr
226226
// passing that should not break things, it appears to... Regardless,
227227
// it should not be needed or useful as those bindings are only available
228228
// to non-static members
229-
TypeResolutionContext typeResCtxt = new TypeResolutionContext.Empty(_typeFactory);
229+
230+
// 27-Oct-2020, tatu: SIGH. As per [databind#2894] there is widespread use of
231+
// incorrect bindings in the wild -- not supported (no tests) but used
232+
// nonetheless. So, for 2.11.x, put back "Bad Bindings"...
233+
// final TypeResolutionContext typeResCtxt = new TypeResolutionContext.Empty(_typeFactory);
234+
final TypeResolutionContext typeResCtxt = _typeContext;
230235

231236
int factoryCount = candidates.size();
232237
List<AnnotatedMethod> result = new ArrayList<>(factoryCount);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.fasterxml.jackson.databind.deser.creators.broken;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.annotation.JsonCreator;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.fasterxml.jackson.core.type.TypeReference;
9+
import com.fasterxml.jackson.databind.*;
10+
11+
// Test(s) to check for handling of Static Factory Creator bindings
12+
// which up until 2.11.2 used type variable bindings of the surrounding
13+
// class for Static methods too. This is semantically wrong, but quite a
14+
// bit of usage existed -- but no one had contributed tests to verify
15+
// this as expected behavior.
16+
// When this usage broken in 2.11.3 -- it was never actually supported but
17+
// happened to sort of work -- reports came in. This test verifies
18+
// assumed behavior so that previous broken (but useful) bindings could
19+
// be brought back for 2.11.4.
20+
//
21+
// Work for 2.12 should find better solution than this.
22+
23+
public class Pre212StaticFactoryImplicitBindingTest extends BaseMapTest
24+
{
25+
// [databind#2894]
26+
static class Wrapper<T> {
27+
List<T> values;
28+
29+
protected Wrapper(List<T> v) {
30+
values = v;
31+
}
32+
33+
public List<T> getValue() { return values; }
34+
35+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
36+
static <T> Wrapper<T> fromValues(@JsonProperty("value") List<T> values) {
37+
return new Wrapper<T>(values);
38+
}
39+
}
40+
41+
static class Value {
42+
public int x;
43+
44+
protected Value() { }
45+
protected Value(int x0) { x = x0; }
46+
47+
@Override
48+
public boolean equals(Object o) {
49+
return (o instanceof Value) && ((Value) o).x == x;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return "[Value x="+x+"]";
55+
}
56+
}
57+
58+
private final ObjectMapper MAPPER = newJsonMapper();
59+
60+
public void testIssue2894() throws Exception
61+
{
62+
Wrapper<Value> src = new Wrapper<>(Arrays.asList(new Value(1), new Value(2)));
63+
final String json = MAPPER.writeValueAsString(src);
64+
Wrapper<Value> output = MAPPER.readValue(json,
65+
new TypeReference<Wrapper<Value>>() {});
66+
assertEquals(src.values, output.values);
67+
}
68+
}

0 commit comments

Comments
 (0)