diff --git a/pom.xml b/pom.xml index 1900792..48ad653 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.sashirestela cleverclient - 1.3.2 + 1.3.3 jar cleverclient diff --git a/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java b/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java index 77736ec..5950900 100644 --- a/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java +++ b/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java @@ -6,6 +6,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; public class ReturnType { @@ -50,25 +51,30 @@ private void setClassByEventIfExists(Method method) { this.classByEvent = calculateClassByEvent( new StreamType[] { method.getDeclaredAnnotation(StreamType.class) }); } else { - var annotations = method.getDeclaredAnnotations(); - if (isAnnotationPresent(annotations, StreamType.List.class)) { + var innerStreamTypeList = getInnerAnnotationIfExists(method, StreamType.List.class); + if (innerStreamTypeList.isPresent()) { this.classByEvent = calculateClassByEvent( - Arrays.stream(annotations) - .map(a -> a.annotationType().getDeclaredAnnotation(StreamType.List.class).value()) - .findFirst() - .orElse(null)); - } else if (isAnnotationPresent(annotations, StreamType.class)) { - this.classByEvent = calculateClassByEvent( - new StreamType[] { Arrays.stream(annotations) - .map(a -> a.annotationType().getDeclaredAnnotation(StreamType.class)) - .findFirst() - .orElse(null) }); + innerStreamTypeList.get() + .annotationType() + .getDeclaredAnnotation(StreamType.List.class) + .value()); + } else { + var innerStreamType = getInnerAnnotationIfExists(method, StreamType.class); + if (innerStreamType.isPresent()) { + this.classByEvent = calculateClassByEvent( + new StreamType[] { innerStreamType.get() + .annotationType() + .getDeclaredAnnotation(StreamType.class) }); + } } } } - private boolean isAnnotationPresent(Annotation[] annotations, Class clazz) { - return Arrays.stream(annotations).anyMatch(a -> a.annotationType().isAnnotationPresent(clazz)); + private Optional getInnerAnnotationIfExists(Method method, + Class clazz) { + return Arrays.stream(method.getDeclaredAnnotations()) + .filter(a -> a.annotationType().isAnnotationPresent(clazz)) + .findFirst(); } private Map> calculateClassByEvent(StreamType[] streamTypeList) { diff --git a/src/test/java/io/github/sashirestela/cleverclient/support/ReturnTypeTest.java b/src/test/java/io/github/sashirestela/cleverclient/support/ReturnTypeTest.java index e16c983..aacccb2 100644 --- a/src/test/java/io/github/sashirestela/cleverclient/support/ReturnTypeTest.java +++ b/src/test/java/io/github/sashirestela/cleverclient/support/ReturnTypeTest.java @@ -1,6 +1,7 @@ package io.github.sashirestela.cleverclient.support; import io.github.sashirestela.cleverclient.Event; +import io.github.sashirestela.cleverclient.annotation.POST; import org.junit.jupiter.api.Test; import java.io.InputStream; @@ -88,6 +89,7 @@ void shouldReturnMapClassByEventWhenTheMethodIsAnnotatedWithCompositeSingleStrea static interface TestInterface { + @POST @CompositeTwo CompletableFuture> asyncStreamEventMethod();