Skip to content

Commit 31a84e2

Browse files
committed
Add a reproduction of #1122 as failing test
1 parent 6875566 commit 31a84e2

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

src/test/java/com/fasterxml/jackson/databind/creators/CreatorPropertiesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.beans.ConstructorProperties;
44

5+
import com.fasterxml.jackson.annotation.JsonProperty;
56
import com.fasterxml.jackson.databind.*;
67

78
public class CreatorPropertiesTest extends BaseMapTest
@@ -21,7 +22,7 @@ public Issue905Bean(int a, int b) {
2122
_y = b;
2223
}
2324
}
24-
25+
2526
/*
2627
/**********************************************************
2728
/* Test methods

src/test/java/com/fasterxml/jackson/databind/creators/TestCreators2.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
package com.fasterxml.jackson.databind.creators;
33

4-
import java.beans.ConstructorProperties;
54
import java.io.IOException;
65
import java.util.List;
76
import java.util.Map;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.beans.ConstructorProperties;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.databind.*;
7+
8+
public class CreatorProperties1122Test extends BaseMapTest
9+
{
10+
static class Issue905Bean {
11+
// 08-Nov-2015, tatu: Note that in real code we would most likely use same
12+
// names for properties; but here we use different name on purpose to
13+
// ensure that Jackson has no way of binding JSON properties "x" and "y"
14+
// using any other mechanism than via `@ConstructorProperties` annotation
15+
public int _x, _y;
16+
17+
@ConstructorProperties({"x", "y"})
18+
// Same as above; use differing local parameter names so that parameter name
19+
// introspection can not be used as the source of property names.
20+
public Issue905Bean(int a, int b) {
21+
_x = a;
22+
_y = b;
23+
}
24+
}
25+
26+
// @JsonIgnoreProperties(ignoreUnknown = true)
27+
public class Ambiguity {
28+
29+
@JsonProperty("bar")
30+
private int foo;
31+
32+
protected Ambiguity() {}
33+
34+
@ConstructorProperties({ "foo" })
35+
public Ambiguity(int foo) {
36+
this.foo = foo;
37+
}
38+
39+
public int getFoo() {
40+
return foo;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "Ambiguity [foo=" + foo + "]";
46+
}
47+
48+
}
49+
/*
50+
/**********************************************************
51+
/* Test methods
52+
/**********************************************************
53+
*/
54+
55+
private final ObjectMapper MAPPER = new ObjectMapper();
56+
57+
// [databind#905]
58+
public void testCreatorPropertiesAnnotation() throws Exception
59+
{
60+
Issue905Bean b = MAPPER.readValue(aposToQuotes("{'y':3,'x':2}"),
61+
Issue905Bean.class);
62+
assertEquals(2, b._x);
63+
assertEquals(3, b._y);
64+
}
65+
66+
public void testIssue1122() throws Exception
67+
{
68+
String json = "{\"bar\":3}";
69+
Ambiguity amb = MAPPER.readValue(json, Ambiguity.class);
70+
assertNotNull(amb);
71+
assertEquals(3, amb.getFoo());
72+
}
73+
}

0 commit comments

Comments
 (0)