diff --git a/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/RetrosheetInterceptor.kt b/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/RetrosheetInterceptor.kt index 41928b9..21685b9 100644 --- a/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/RetrosheetInterceptor.kt +++ b/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/RetrosheetInterceptor.kt @@ -43,18 +43,24 @@ private constructor( private fun isReturnTypeList(request: Request): Boolean { val method = request.tag(Invocation::class.java)?.method() - val genericReturnType = method?.genericReturnType?.toString() - return if (genericReturnType != null && genericReturnType != TYPE_OBJECT) { - genericReturnType.contains(PACKAGE_LIST_CONTAINS) + val hasReadAsList = method?.annotations?.indexOfFirst { it is ReadAsList } != -1 + if (hasReadAsList) { + return true } else { - // go for hard reflection - try { - val f = Method::class.java.getDeclaredField("signature") - f.isAccessible = true - val signature = f.get(method).toString() - signature.contains(SIGNATURE_LIST_CONTAINS) - } catch (e: NoSuchFieldException) { - false + // Trying to find return type using reflection + val genericReturnType = method?.genericReturnType?.toString() + return if (genericReturnType != null && genericReturnType != TYPE_OBJECT) { + genericReturnType.contains(PACKAGE_LIST_CONTAINS) + } else { + // go for hard reflection + try { + val f = Method::class.java.getDeclaredField("signature") + f.isAccessible = true + val signature = f.get(method).toString() + signature.contains(SIGNATURE_LIST_CONTAINS) + } catch (e: NoSuchFieldException) { + false + } } } diff --git a/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/core/ReadAsList.kt b/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/core/ReadAsList.kt new file mode 100644 index 0000000..150eb8c --- /dev/null +++ b/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/core/ReadAsList.kt @@ -0,0 +1,9 @@ +package com.github.theapache64.retrosheet.core + +/** + * To tell Retrosheet that the method expects List/multiple items + */ +@MustBeDocumented +@Target(AnnotationTarget.FUNCTION) +@Retention +annotation class ReadAsList \ No newline at end of file