Skip to content

Commit b6f3f6a

Browse files
Test for lost annotations
1 parent c52fb0b commit b6f3f6a

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ public void remove() {
10561056
* Node used for creating simple linked lists to efficiently store small sets
10571057
* of things.
10581058
*/
1059-
private final static class Linked<T>
1059+
protected final static class Linked<T>
10601060
{
10611061
public final T value;
10621062
public final Linked<T> next;

src/test/java/com/fasterxml/jackson/databind/introspect/TestPOJOPropertiesCollector.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.fasterxml.jackson.databind.introspect;
22

3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
37
import java.math.BigDecimal;
48
import java.util.*;
59

@@ -198,7 +202,35 @@ static class PropDescBean
198202
@JsonProperty(required=true, index=B_INDEX, defaultValue="13")
199203
public int getB() { return b; }
200204
}
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+
202234
/*
203235
/**********************************************************
204236
/* Unit tests
@@ -433,6 +465,30 @@ public void testPropertyIndex() throws Exception
433465
_verifyProperty(beanDesc, false, true, "13");
434466
}
435467

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+
436492
private void _verifyProperty(BeanDescription beanDesc,
437493
boolean verifyDesc, boolean verifyIndex, String expDefaultValue)
438494
{

0 commit comments

Comments
 (0)