users@jersey.java.net

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

From: Graham Leggett <minfrin_at_sharp.fm>
Date: Sat, 15 Mar 2014 01:44:21 +0200

On 14 Mar 2014, at 8:09 PM, cowwoc <cowwoc_at_bbs.darktech.org> wrote:

> 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 then all of 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.

I am not seeing jersey work with interfaces at all.

I have annotations in interfaces autogenerated by wadl2java, and a concrete implementation class that implements the interface. By default, eclipse autgenerates concrete classes with the @Override annotation. The concrete implementation class is completely ignored by jersey.

I tried removing all the @Override annotations, as I believe the bug you have listed above requires. Makes no difference, jersey completely ignores the concrete classes.

I tried moving the concrete implementation class into a dedicated package and pointing jersey at that new package, keeping the interface outside in another package. No joy, jersey utterly ignores the concrete class.

I feel like I am in the twilight zone. wadl2java generates interface code. People on various mailing lists tell me that yes, interface code does work. But I find no concrete examples of it working, no clues as to what to do differently to make it work, and nobody can explain what to do differently to make it work.

Has anyone got an actual working, running example of jersey in an interface?

Regards,
Graham
--