users@jersey.java.net

[Jersey] Re: Inheritance and Internal Classes

From: Adam Walczak <me_at_adamwalczak.info>
Date: Wed, 22 Dec 2010 23:53:06 +0100

Hello,

> @Path("/simple")
> public class Simple {
>  @Path("/resource1")
>  public class ResourceOne{
>    public ResourceOne() { super("arg value"); }
>  }
>  @Path("/resource2")
>  public class ResourceTwo{
>    public ResourceTwo() { super("arg value"); }
>  }
> }

I don't think this type of nesting is anywhere in the JAX-RS spec.
Sub-resources work differently. If you want sub-resources to be nested
classes you should do something like this:

@Path("/simple")
public class Simple {

 public class ResourceOne{
   public ResourceOne() { super("arg value"); }
 }

 @Path("/resource1")
 public ResourceOne getResourceOne() {
     return new ResourceOne();
 }

 public class ResourceTwo{
   public ResourceTwo() { super("arg value"); }
 }

 @Path("/resource2")
 public ResourceTwo getResourceTwo() {
     return new ResourceTwo();
 }
}

-- 
Adam Walczak
www.adamwalczak.info
+48 604 188 992