@@ -168,6 +168,41 @@ public static class NoKeyOuter {
168168 }
169169 }
170170
171+ // [databind#6240]: same as `Outer2871`, but annotations on getter
172+ static class OuterWithGetter6240 {
173+ private final Inner2871 inner ;
174+
175+ OuterWithGetter6240 (Inner2871 inner ) {
176+ this .inner = inner ;
177+ }
178+
179+ @ JsonKey
180+ @ JsonValue
181+ public Inner2871 getInner () {
182+ return inner ;
183+ }
184+ }
185+
186+ // [databind#6240]
187+ static class KeyOnlyGetter6240 {
188+ public String name = "value" ;
189+
190+ @ JsonKey
191+ @ JsonValue (false )
192+ public String getId () {
193+ return "a" ;
194+ }
195+ }
196+
197+ // [databind#6240]
198+ static class ValueOnlyGetter6240 {
199+ @ JsonKey (false )
200+ @ JsonValue
201+ public String getId () {
202+ return "a" ;
203+ }
204+ }
205+
171206 // // // Inner types from MapKeySerializationTest
172207
173208 static class KarlSerializer extends ValueSerializer <String >
@@ -487,6 +522,37 @@ public void testNoKeyOuter() throws Exception {
487522 assertEquals ("{\" key\" :\" innerValue\" }" , actual );
488523 }
489524
525+ // [databind#6240]
526+ @ Test
527+ public void testClassAsKeyWithGetter () throws Exception {
528+ OuterWithGetter6240 outer = new OuterWithGetter6240 (new Inner2871 ("innerKey" , "innerValue" ));
529+ assertEquals ("{\" innerKey\" :\" value\" }" ,
530+ MAPPER .writeValueAsString (Collections .singletonMap (outer , "value" )));
531+ }
532+
533+ // [databind#6240]
534+ @ Test
535+ public void testClassAsValueWithGetter () throws Exception {
536+ OuterWithGetter6240 outer = new OuterWithGetter6240 (new Inner2871 ("innerKey" , "innerValue" ));
537+ assertEquals ("\" innerValue\" " , MAPPER .writeValueAsString (outer ));
538+ assertEquals ("{\" key\" :\" innerValue\" }" ,
539+ MAPPER .writeValueAsString (Collections .singletonMap ("key" , outer )));
540+ }
541+
542+ // [databind#6240]: disabled `@JsonValue` must not expose key getter as property
543+ @ Test
544+ public void testKeyOnlyGetter () throws Exception {
545+ assertEquals ("{\" name\" :\" value\" }" , MAPPER .writeValueAsString (new KeyOnlyGetter6240 ()));
546+ assertEquals ("{\" a\" :1}" ,
547+ MAPPER .writeValueAsString (Collections .singletonMap (new KeyOnlyGetter6240 (), 1 )));
548+ }
549+
550+ // [databind#6240]: disabled `@JsonKey` must not disable `@JsonValue`
551+ @ Test
552+ public void testValueOnlyGetter () throws Exception {
553+ assertEquals ("\" a\" " , MAPPER .writeValueAsString (new ValueOnlyGetter6240 ()));
554+ }
555+
490556 // // // Tests from MapKeySerializationTest
491557
492558 @ Test
0 commit comments