rest
rest copied to clipboard
Enhancement Proposal: ResourceInfo.getAnnotation(Class annotationClass)
I hereby propose the addition of the following method:
public <A extends Annotation> A ResourceInfo.getResourceAnnotation(Class<A> annotationClass)
The idea is that this method returns the annotation instance of the given annotationClass with full respect to the rules found in spec chapter 3.6. This effectively means, this method returns either the super class annotation, or the interface annotation, or the resource class annotation, or the resource method annotation, depending on whether any JAX-RS annotation is found in the particular deeper levels.
The benefit of this method is that there is no need for filters / interceptors to re-implement this algorithm again and again for custom annotations, in case the annotation author wants to apply the same rules as found in chapter 3.6 (hence: the new annotation shall "look and feel" like an official JAX-RS annotation). Implementations could make the already existing algorithm publicly available here, so it is guaranteed that the exact same treatment happens for custom annotations and for official annotations.
Kindly asking for more opinions, in particular from committers.
If nobody vetos ResourceInfo.getResourceAnnotations upfront, I will provide a PR and compliant implementation (PR for Jersey) in the next weeks.
There had been not upfront vetos, so I assume everybody is fine with adopting this enhancement. If not, please clearly tell me NOW. Thanks.
When moving to CDI, I hope the annotation operations can be by CDI utilities directly. Currently, almost every spec has some util to handle the reflection-related operations.
Should there ba a getResourceClassAnnotations() and/or getResourceMethodAnnotations()?
@mkarg Thanks for bringing this up. I like the idea. We actually had to reimplement the annotation inheritance rules for the MVC spec implementation as well. So +1 for this idea. Just one though: Shouldn't it be getResourceAnnotation instead of getResourceAnnotations (so singular instead of plural)?
Should there ba a
getResourceClassAnnotations()and/orgetResourceMethodAnnotations()?
I personally don't see a real benefit of having these. Especially separate ones for class- and method-level annotations.
Should there ba a
getResourceClassAnnotations()and/orgetResourceMethodAnnotations()?
Never had the actual need this separation.
Shouldn't it be
getResourceAnnotationinstead ofgetResourceAnnotations(so singular instead of plural)?
Correct, I ~will fix~ fixed the original description.
As nobody vetoed, I have sketched a first draft. I think it makes sense to continue our discussion there.
Seems like a useful addition, as is the suggestion to support lookup for methods as well I think.