Skip to content

Commit 74accd6

Browse files
committed
Add test from #2895
1 parent 461cf3d commit 74accd6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/creators/broken/Pre212StaticFactoryImplicitBindingTest.java

+49
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import com.fasterxml.jackson.annotation.JsonCreator;
77
import com.fasterxml.jackson.annotation.JsonProperty;
8+
89
import com.fasterxml.jackson.core.type.TypeReference;
10+
911
import com.fasterxml.jackson.databind.*;
1012

1113
// Test(s) to check for handling of Static Factory Creator bindings
@@ -55,8 +57,43 @@ public String toString() {
5557
}
5658
}
5759

60+
// [databind#2895]
61+
static class SimpleWrapper2895<T> {
62+
final T value;
63+
64+
SimpleWrapper2895(T value) {
65+
this.value = value;
66+
}
67+
68+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
69+
public static <T> SimpleWrapper2895<T> fromJson(JsonSimpleWrapper2895<T> value) {
70+
return new SimpleWrapper2895<>(value.object);
71+
}
72+
}
73+
74+
static final class JsonSimpleWrapper2895<T> {
75+
@JsonProperty("object")
76+
public T object;
77+
}
78+
79+
static class Account2895 {
80+
private long id;
81+
private String name;
82+
83+
@JsonCreator
84+
public Account2895(@JsonProperty("name") String name,
85+
@JsonProperty("id") long id) {
86+
this.id = id;
87+
this.name = name;
88+
}
89+
90+
public String getName() { return name; }
91+
public long getId() { return id; }
92+
}
93+
5894
private final ObjectMapper MAPPER = newJsonMapper();
5995

96+
// [databind#2894]
6097
public void testIssue2894() throws Exception
6198
{
6299
Wrapper<Value> src = new Wrapper<>(Arrays.asList(new Value(1), new Value(2)));
@@ -65,4 +102,16 @@ public void testIssue2894() throws Exception
65102
new TypeReference<Wrapper<Value>>() {});
66103
assertEquals(src.values, output.values);
67104
}
105+
106+
// [databind#2895]
107+
public void testIssue2895() throws Exception
108+
{
109+
SimpleWrapper2895<Account2895> wrapper = MAPPER
110+
.readerFor(new TypeReference<SimpleWrapper2895<Account2895>>() {})
111+
.readValue("{\"object\":{\"id\":1,\"name\":\"name1\"}}");
112+
113+
Account2895 account = wrapper.value;
114+
assertEquals(1, account.getId());
115+
assertEquals("name1", account.getName());
116+
}
68117
}

0 commit comments

Comments
 (0)