4
4
5
5
import com .fasterxml .jackson .databind .BaseMapTest ;
6
6
import com .fasterxml .jackson .databind .ObjectMapper ;
7
+ import com .fasterxml .jackson .databind .introspect .*;
7
8
8
9
public class IgnoredCreatorProperty1572Test extends BaseMapTest
9
10
{
@@ -15,15 +16,37 @@ static class InnerTest
15
16
16
17
static class OuterTest
17
18
{
18
- InnerTest inner ;
19
+ InnerTest innerTest ;
19
20
20
21
@ JsonIgnore
21
- public String otherStr ;
22
+ String otherOtherStr ;
22
23
23
24
@ JsonCreator
24
- public OuterTest (@ JsonProperty ("inner" ) InnerTest inner ,
25
- @ JsonProperty ("otherOtherStr" ) String otherStr ) {
26
- this .inner = inner ;
25
+ public OuterTest (/*@JsonProperty("innerTest")*/ InnerTest inner ,
26
+ /*@JsonProperty("otherOtherStr")*/ String otherStr ) {
27
+ this .innerTest = inner ;
28
+ }
29
+ }
30
+
31
+ static class ImplicitNames extends JacksonAnnotationIntrospector
32
+ {
33
+ private static final long serialVersionUID = 1L ;
34
+
35
+ @ Override
36
+ public String findImplicitPropertyName (AnnotatedMember member ) {
37
+ if (member instanceof AnnotatedParameter ) {
38
+ // A placeholder for legitimate property name detection
39
+ // such as what the JDK8 module provides
40
+ AnnotatedParameter param = (AnnotatedParameter ) member ;
41
+ switch (param .getIndex ()) {
42
+ case 0 :
43
+ return "innerTest" ;
44
+ case 1 :
45
+ return "otherOtherStr" ;
46
+ default :
47
+ }
48
+ }
49
+ return null ;
27
50
}
28
51
}
29
52
@@ -33,16 +56,18 @@ public OuterTest(@JsonProperty("inner") InnerTest inner,
33
56
/********************************************************
34
57
*/
35
58
36
- private final ObjectMapper MAPPER = new ObjectMapper ();
37
-
38
59
// [databind#1572]
39
60
public void testIgnoredCtorParam () throws Exception
40
61
{
62
+ final ObjectMapper mapper = new ObjectMapper ();
63
+ mapper .setAnnotationIntrospector (new ImplicitNames ());
41
64
String JSON = aposToQuotes ("{'innerTest': {\n "
42
65
+"'str':'str',\n "
43
66
+"'otherStr': 'otherStr'\n "
44
67
+"}}\n " );
45
- OuterTest result = MAPPER .readValue (JSON , OuterTest .class );
68
+ OuterTest result = mapper .readValue (JSON , OuterTest .class );
46
69
assertNotNull (result );
70
+ assertNotNull (result .innerTest );
71
+ assertEquals ("otherStr" , result .innerTest .otherStr );
47
72
}
48
73
}
0 commit comments