Skip to content

Commit eb6336b

Browse files
committed
Merge branch '2.11' into 2.12
2 parents 29cc17a + 461cf3d commit eb6336b

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,10 @@ Daniel Wu (DanielYWoo@github)
11641164
* Reported #2840: `ObjectMapper.activateDefaultTypingAsProperty()` is not using
11651165
(2.11.3)
11661166
1167+
Łukasz Walkiewicz (lukasz-walkiewicz@github)
1168+
* Reported #2894: Fix type resolution for static methods (regression in 2.11.3)
1169+
(2.11.4)
1170+
11671171
Marc Carter (drekbour@github)
11681172
* Contributed #43 implementation: Add option to resolve type from multiple existing properties,
11691173
`@JsonTypeInfo(use=DEDUCTION)`

release-notes/VERSION-2.x

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
87
2.12.0-rc2 (not yet released)
98

109
#1458: `@JsonAnyGetter` should be allowed on a field
@@ -92,6 +91,11 @@ Project: jackson-databind
9291
- Add `BeanDeserializerBase.isCaseInsensitive()`
9392
- Some refactoring of `CollectionDeserializer` to solve CSV array handling issues
9493

94+
2.11.4 (not yet released)
95+
96+
#2894: Fix type resolution for static methods (regression in 2.11.3 due to #2821 fix)
97+
(reported by Łukasz W)
98+
9599
2.11.3 (02-Oct-2020)
96100

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
214214
// passing that should not break things, it appears to... Regardless,
215215
// it should not be needed or useful as those bindings are only available
216216
// to non-static members
217-
TypeResolutionContext typeResCtxt = new TypeResolutionContext.Empty(typeFactory);
217+
// final TypeResolutionContext typeResCtxt = new TypeResolutionContext.Empty(typeFactory);
218+
219+
// 27-Oct-2020, tatu: SIGH. As per [databind#2894] there is widespread use of
220+
// incorrect bindings in the wild -- not supported (no tests) but used
221+
// nonetheless. So, for 2.11.x, put back "Bad Bindings"...
222+
final TypeResolutionContext typeResCtxt = _typeContext;
218223

219224
int factoryCount = candidates.size();
220225
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+
}

src/test/java/com/fasterxml/jackson/databind/ser/GenericTypeSerializationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ public void testTypeResolution2821() throws Exception
255255
list = (List<Entity2821<?>>) (List<?>) foo;
256256
}
257257
Wrapper2821 val = new Wrapper2821(list);
258-
// fails with com.fasterxml.jackson.databind.JsonMappingException: Strange Map type java.util.Map: cannot determine type parameters (through reference chain: com.github.lhotari.jacksonbug.JacksonBugIsolatedTest$Wrapper["entities"]->java.util.Collections$SingletonList[0]->com.github.lhotari.jacksonbug.JacksonBugIsolatedTest$Entity["attributes"])
258+
// Was failing with `com.fasterxml.jackson.databind.JsonMappingException`: Strange Map
259+
// type java.util.Map: cannot determine type parameters (through reference chain: ---)
259260
String json = MAPPER.writeValueAsString(val);
260261
assertNotNull(json);
261262
}

0 commit comments

Comments
 (0)