Skip to content

Commit 0bb4750

Browse files
authored
Merge pull request #1752 from deki/reintroduce-annotations
Reintroduce Annotated.annotations() method as deprecated
2 parents 4cd4140 + a6a999c commit 0bb4750

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public Type getGenericType() {
7676
*/
7777
public abstract Class<?> getRawType();
7878

79+
/**
80+
* Accessor that can be used to iterate over all the annotations
81+
* associated with annotated component.
82+
*
83+
* @since 2.3
84+
* @deprecated Since 2.9 should instead use {@link #getAnnotated()}
85+
*/
86+
@Deprecated
87+
public abstract Iterable<Annotation> annotations();
88+
7989
// Also: ensure we can use #equals, #hashCode
8090

8191
@Override

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ public Class<?> getRawType() {
247247
return _class;
248248
}
249249

250+
@Override
251+
@Deprecated
252+
public Iterable<Annotation> annotations() {
253+
if (_classAnnotations instanceof AnnotationMap) {
254+
return ((AnnotationMap) _classAnnotations).annotations();
255+
} else if (_classAnnotations instanceof AnnotationCollector.OneAnnotation ||
256+
_classAnnotations instanceof AnnotationCollector.TwoAnnotations) {
257+
throw new UnsupportedOperationException("please use getAnnotations/ hasAnnotation to check for Annotations");
258+
}
259+
return Collections.emptyList();
260+
}
261+
250262
@Override
251263
public JavaType getType() {
252264
return _type;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.annotation.Annotation;
44
import java.lang.reflect.Member;
5+
import java.util.Collections;
56

67
import com.fasterxml.jackson.databind.util.ClassUtil;
78

@@ -103,6 +104,15 @@ public boolean hasOneOf(Class<? extends Annotation>[] annoClasses) {
103104
return _annotations.hasOneOf(annoClasses);
104105
}
105106

107+
@Override
108+
@Deprecated
109+
public Iterable<Annotation> annotations() {
110+
if (_annotations == null) {
111+
return Collections.emptyList();
112+
}
113+
return _annotations.annotations();
114+
}
115+
106116
/**
107117
*<p>
108118
* NOTE: promoted in 2.9 from `Annotated` up

0 commit comments

Comments
 (0)