Hi,
I just discovered (...in the hard way...) that annotations are not
inherited in JAX-RS/Jersey. This is - in my opinion - quite
unfortunate.
Suppose I have
abstract class Base {
@Path("foo") Response getContents();
}
class Concrete extends Base {
@Override
@Produces("application/xml") Response getContents() { ... }
}
(assuming that Concrete will be returned as a sub-locator in some place).
Now if you try to GET /some/path/foo, you will get a 404, as Jersey is
unaware of the @Path annotation on getContents. This makes it quite
hard to properly use inheritance for resources. You can either have
all annotations on the Concrete method, or you can have all
annotations on the parent, make that method final, and introduce e.g.
an abstract method for inheriting classes to extend. However in the
latter case the extending class cannot add any annotations.
If I understand the rationale behind the behaviour of
class.getAnnotations(...) in Java reflection correctly, then the idea
is that tools should "manually" check annotations for all
superclasses/superinterfaces if they wish to do so (by going through
getSuperinterfaces/getSuperclass). Is there any reason why Jersey
doesn't do this, or is this just an omission? Can we have this?
Regards
Martin