11package tools .jackson .databind .deser ;
22
3+ import java .beans .ConstructorProperties ;
4+
35import org .junit .jupiter .api .Test ;
46
57import tools .jackson .databind .MapperFeature ;
@@ -27,6 +29,21 @@ public Bean178(String openName, int openAge) {
2729 }
2830 }
2931
32+ // [databind#6229]: same shape as Bean178 above, but with `@ConstructorProperties`
33+ // added -- specifically to validate Jackson 2.x compatibility, `@ConstructorProperties`
34+ // must keep resolving names regardless of `DETECT_PARAMETER_NAMES`.
35+ static class CtorPropsBean6229
36+ {
37+ final String hiddenName ;
38+ final int hiddenAge ;
39+
40+ @ ConstructorProperties ({"openName" , "openAge" })
41+ public CtorPropsBean6229 (String openName , int openAge ) {
42+ hiddenName = openName ;
43+ hiddenAge = openAge ;
44+ }
45+ }
46+
3047 private final String JSON = a2q ("{'openName':'stu','openAge':22}" );
3148
3249 @ Test
@@ -46,10 +63,29 @@ public void testWorksByDefault()
4663 .builderWithJackson2Defaults ().build ());
4764 }
4865
66+ // [databind#6229]: `CtorPropsBean178` (see above) must deserialize
67+ // successfully under all three configs below.
68+ @ Test
69+ public void testConstructorPropertiesIgnoresDetectParameterNames ()
70+ {
71+ _runCtorPropsSuccess (JsonMapper .builder ()
72+ .enable (MapperFeature .DETECT_PARAMETER_NAMES ).build ());
73+ _runCtorPropsSuccess (JsonMapper .builder ()
74+ .disable (MapperFeature .DETECT_PARAMETER_NAMES ).build ());
75+ _runCtorPropsSuccess (JsonMapper
76+ .builderWithJackson2Defaults ().build ());
77+ }
78+
4979 private void _runTestSuccess (JsonMapper mapper )
5080 {
5181 Bean178 bean = mapper .readValue (JSON , Bean178 .class );
82+ assertEquals ("stu" , bean .hiddenName );
83+ assertEquals (22 , bean .hiddenAge );
84+ }
5285
86+ private void _runCtorPropsSuccess (JsonMapper mapper )
87+ {
88+ CtorPropsBean6229 bean = mapper .readValue (JSON , CtorPropsBean6229 .class );
5389 assertEquals ("stu" , bean .hiddenName );
5490 assertEquals (22 , bean .hiddenAge );
5591 }
0 commit comments