users@jersey.java.net

Re: [Jersey] Inheritance of Annotations and Jersey?

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 08 Jul 2009 11:03:40 -0400

There is a limited form of annotation inheritance, for details see here:

https://jsr311.dev.java.net/nonav/releases/1.0/spec/
spec3.html#x3-330003.6

The issue you are running into is that you have @Produces on the
overriding method which nullifies the @Path on the overridden method.

Marc.

On Jul 8, 2009, at 9:18 AM, Martin Probst wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>