|
| 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