users@jersey.java.net

Re: [Jersey] Jersey resources with inheritance giving 'Producing media type conflict' exception

From: ManiKanta G <go4mani_at_gmail.com>
Date: Mon, 6 Sep 2010 12:31:44 +0530

Hi,

Excuse me for the late reply. Please follow my inline comments.


This is a deployment error.


I didn't get this. You mean the way I deploy the app or any Jersey build
error?


> Resources classes will inherit methods from a super class (as is the case
> with normal inheritance), and in this case there is a conlifct for
> ChildResource. There are two resource methods producing the same media type
> resulting in an ambiguity on what method to invoke.
>

Yeah, I can guess this behavior. But I m clueless as when accessing the
parent resource (/parent) also I m getting this conflict. I suppose parent
resource will not look into child resource. Isn't it?
just quoting part of my original mail:

> Most confusing behavior (yeah, even than the above) is parent resource is
>> requested, through /parent, still I m getting this media type ambiguity
>> error. When a resource was request why is it searching in its child
>> resource.
>>
>

You need to do this:
>
> @Path("/child")
> public class ChildResource extends ParentResource {
> @Override
>
> @GET
> @Produces("text/plain")
> public String getFromParent() {
> System.out.println("Child resource method");
> return "Response from child";
> }
> }
>
>
Yeah, I tried this. But the child method is returning incompatible object
type with the parent method return type (as Java only allows same or
co-variant return types), I m required to change the name (but that
difference was not shown in this example; I just made the example simple to
demonstrate the behavior)

Thanks again.

ManiKanta G
twitter.com/ManiKantaG