@@ -89,6 +89,11 @@ public static String getResourcePath(final Class<?> resource) {
8989 * @throws java.lang.IllegalStateException if annotation not found
9090 */
9191 public static String getMethodPath (final Method method ) {
92+ final Path path = method .getAnnotation (Path .class );
93+ if (path == null ) {
94+ // method might miss path annotation if the path is the same as resource path
95+ return "/" ;
96+ }
9297 return PathUtils .normalizeAbsolutePath (findAnnotatedMethod (method ).getAnnotation (Path .class ).value ());
9398 }
9499
@@ -192,18 +197,18 @@ public static Method findMethod(final Class<?> resource, final String method) {
192197 */
193198 public static Method findAnnotatedMethod (final Method method ) {
194199 Method res = null ;
195- // searching for annotated method
196- if (method . getAnnotation ( Path . class ) == null ) {
200+ // searching for annotated method (could be Path or method annotation)
201+ if (! isJerseyAnnotated ( method ) ) {
197202 // try to search in superclasses and interfaces (for declaring class!)
198203 for (Class <?> type : GenericsResolver .resolve (method .getDeclaringClass ())
199204 .getGenericsInfo ().getComposingTypes ()) {
200205 for (Method cand : type .getDeclaredMethods ()) {
201206 // searching same method, but annotated
202207 if (cand .getName ().equals (method .getName ())
203208 && cand .getParameterTypes ().length == method .getParameterTypes ().length
204- && cand .getAnnotation (Path .class ) != null
205209 // not count possible type differences
206- && Arrays .equals (cand .getParameterTypes (), method .getParameterTypes ())) {
210+ && Arrays .equals (cand .getParameterTypes (), method .getParameterTypes ())
211+ && isJerseyAnnotated (cand )) {
207212 res = cand ;
208213 break ;
209214 }
@@ -220,6 +225,21 @@ public static Method findAnnotatedMethod(final Method method) {
220225 return res ;
221226 }
222227
228+ /**
229+ * Check if provided method is annotated with jersey annotations. Http methods must have http method
230+ * annotation (like {@link jakarta.ws.rs.GET}), but may lack {@link jakarta.ws.rs.Path} annotation.
231+ * Sub-resource lookup method must have {@link Path annotation}. So target method must be checked to contain
232+ * one of possible annotations.
233+ * <p>
234+ * Note that it is impossible to have Path and http method annotation on different methods (jersey requirement).
235+ *
236+ * @param method method to check
237+ * @return true if method contains jersey annotations
238+ */
239+ public static boolean isJerseyAnnotated (final Method method ) {
240+ return method .getAnnotation (Path .class ) != null || getHttpMethod (method ).isPresent ();
241+ }
242+
223243 /**
224244 * Resolve http method by searching for method annotations like {@link jakarta.ws.rs.GET} or
225245 * {@link jakarta.ws.rs.POST}.
0 commit comments