users@jersey.java.net

[Jersey] Re: Annotations in interfaces, how to use with jersey?

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Fri, 14 Mar 2014 14:09:08 -0400

No. That's not the case. The way JAX-RS treats annotation inheritance is
totally screwed up:
https://jsr311.java.net/nonav/releases/1.0/spec/spec3.html#x3-330003.6

"If a subclass or implementation method has any JAX-RS annotations
thenallof the annotations on the super class or interface method are
ignored."

In other words, if you annotate implemented methods with @Override
(because, uh, we're *supposed* to) or even if you annotate your method
parameters (think @Context) then JAX-RS will drop all your interface
annotations. I absolutely hate the way this was designed.

I filed a bug report at https://java.net/jira/browse/JERSEY-1885 but
based on "Fix Version" it doesn't look like it's going anywhere.

Gili

On 14/03/2014 1:05 PM, Graham Leggett wrote:
> On 14 Mar 2014, at 6:42 PM, Guy Rouillier <guy.rouillier_at_gmail.com> wrote:
>
>> We encountered the same issue. The simplest solution is to move your interfaces to a different package. That was a better solution for us in the long run anyway; we exported the interface package to a client JAR to be used with the client proxy.
> Am I right in understanding that if jersey finds a concrete class, and the class implements a given interface with the required annotations, jersey will just "do the right thing" and treat the annotations as if they had been applied directly to the concrete class, interface and concrete class just need to be in different packages?
>
> Regards,
> Graham
> --
>