|
1 | 1 | package com.fasterxml.jackson.databind.introspect;
|
2 | 2 |
|
| 3 | +import java.lang.annotation.ElementType; |
| 4 | +import java.lang.annotation.Retention; |
| 5 | +import java.lang.annotation.RetentionPolicy; |
| 6 | +import java.lang.annotation.Target; |
3 | 7 | import java.math.BigDecimal;
|
4 | 8 | import java.util.*;
|
5 | 9 |
|
@@ -198,7 +202,35 @@ static class PropDescBean
|
198 | 202 | @JsonProperty(required=true, index=B_INDEX, defaultValue="13")
|
199 | 203 | public int getB() { return b; }
|
200 | 204 | }
|
201 |
| - |
| 205 | + |
| 206 | + @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) |
| 207 | + @Retention(RetentionPolicy.RUNTIME) |
| 208 | + @JacksonAnnotation |
| 209 | + @interface A {} |
| 210 | + |
| 211 | + @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) |
| 212 | + @Retention(RetentionPolicy.RUNTIME) |
| 213 | + @JacksonAnnotation |
| 214 | + @interface B {} |
| 215 | + |
| 216 | + static class DuplicateGetterBean |
| 217 | + { |
| 218 | + @A |
| 219 | + public boolean isBloop() { return true; } |
| 220 | + |
| 221 | + @B |
| 222 | + public boolean getBloop() { return true; } |
| 223 | + } |
| 224 | + |
| 225 | + static class DuplicateGetterCreatorBean |
| 226 | + { |
| 227 | + public DuplicateGetterCreatorBean(@JsonProperty("bloop") @A boolean bloop) {} |
| 228 | + |
| 229 | + public boolean isBloop() { return true; } |
| 230 | + |
| 231 | + public boolean getBloop() { return true; } |
| 232 | + } |
| 233 | + |
202 | 234 | /*
|
203 | 235 | /**********************************************************
|
204 | 236 | /* Unit tests
|
@@ -433,6 +465,30 @@ public void testPropertyIndex() throws Exception
|
433 | 465 | _verifyProperty(beanDesc, false, true, "13");
|
434 | 466 | }
|
435 | 467 |
|
| 468 | + public void testDuplicateGetters() throws Exception |
| 469 | + { |
| 470 | + POJOPropertiesCollector coll = collector(MAPPER, DuplicateGetterBean.class, true); |
| 471 | + List<BeanPropertyDefinition> props = coll.getProperties(); |
| 472 | + assertEquals(1, props.size()); |
| 473 | + BeanPropertyDefinition prop = props.get(0); |
| 474 | + assertEquals("bloop", prop.getName()); |
| 475 | + assertTrue(prop.getGetter().hasAnnotation(A.class)); |
| 476 | + assertTrue(prop.getGetter().hasAnnotation(B.class)); |
| 477 | + } |
| 478 | + |
| 479 | + public void testDuplicateGettersCreator() throws Exception |
| 480 | + { |
| 481 | + POJOPropertiesCollector coll = collector(MAPPER, DuplicateGetterCreatorBean.class, true); |
| 482 | + List<BeanPropertyDefinition> props = coll.getProperties(); |
| 483 | + assertEquals(1, props.size()); |
| 484 | + POJOPropertyBuilder prop = (POJOPropertyBuilder) props.get(0); |
| 485 | + assertEquals("bloop", prop.getName()); |
| 486 | + // Can't call getGetter or the duplicate will be removed |
| 487 | + assertTrue(prop._getters.value.hasAnnotation(A.class)); |
| 488 | + assertNotNull(prop._getters.next); |
| 489 | + assertTrue(prop._getters.next.value.hasAnnotation(A.class)); |
| 490 | + } |
| 491 | + |
436 | 492 | private void _verifyProperty(BeanDescription beanDesc,
|
437 | 493 | boolean verifyDesc, boolean verifyIndex, String expDefaultValue)
|
438 | 494 | {
|
|
0 commit comments