11package tools .jackson .module .guice ;
22
3+ import java .lang .annotation .Annotation ;
4+ import java .util .stream .Stream ;
5+ import javax .inject .Qualifier ;
6+
37import com .fasterxml .jackson .annotation .JacksonInject ;
48import tools .jackson .databind .cfg .MapperConfig ;
59import tools .jackson .databind .introspect .*;
610import com .google .inject .BindingAnnotation ;
711import com .google .inject .Key ;
812
9- import javax .inject .Qualifier ;
10- import java .lang .annotation .Annotation ;
11- import java .util .Arrays ;
12-
1313public class GuiceAnnotationIntrospector extends NopAnnotationIntrospector
1414{
1515 private static final long serialVersionUID = 1L ;
@@ -50,8 +50,7 @@ private Object _findGuiceInjectId(AnnotatedMember m)
5050 // On fields and parameters the @Qualifier annotation and type to
5151 // inject are the member itself, so, nothing to do here...
5252 guiceMember = m ;
53- AnnotationMap anns = ((AnnotatedMember ) m ).getAllAnnotations ();
54- guiceAnnotation = findBindingAnnotation (anns .annotations ());
53+ guiceAnnotation = findBindingAnnotation (m .annotations ());
5554 } else if (m instanceof AnnotatedMethod ) {
5655 /* For method injection, the @Qualifier and type to inject are
5756 * specified on the parameter. Here, we only consider methods with
@@ -68,7 +67,7 @@ private Object _findGuiceInjectId(AnnotatedMember m)
6867 */
6968 guiceMember = a .getParameter (0 );
7069 final Annotation [] annotations = a .getMember ().getParameterAnnotations ()[0 ];
71- guiceAnnotation = findBindingAnnotation (Arrays . asList (annotations ));
70+ guiceAnnotation = findBindingAnnotation (Stream . of (annotations ));
7271 } else {
7372 /* Ignore constructors */
7473 return null ;
@@ -93,16 +92,14 @@ private Object _findGuiceInjectId(AnnotatedMember m)
9392 * annotation are present on what we're trying to inject.
9493 * Those annotations are only possible on fields or parameters.
9594 */
96- private Annotation findBindingAnnotation (Iterable <Annotation > annotations )
95+ private Annotation findBindingAnnotation (Stream <Annotation > annotations )
9796 {
98- for (Annotation annotation : annotations ) {
99- // Check on guice (BindingAnnotation) & javax (Qualifier) based injections
100- if (annotation .annotationType ().isAnnotationPresent (BindingAnnotation .class ) ||
101- annotation .annotationType ().isAnnotationPresent (Qualifier .class ))
102- {
103- return annotation ;
104- }
105- }
106- return null ;
97+ return annotations .filter (ann -> {
98+ Class <?> type = ann .annotationType ();
99+ return type .isAnnotationPresent (BindingAnnotation .class )
100+ || type .isAnnotationPresent (Qualifier .class );
101+ })
102+ .findFirst ()
103+ .orElse (null );
107104 }
108105}
0 commit comments