users@jersey.java.net

Null as pathparam

From: Yoryos <valotas_at_gmail.com>
Date: Sun, 1 Aug 2010 00:54:50 +0300

Hi all, I'll try to describe my question with an example: I have the above
resource class:

@Path("ctx/{ctxId}")
public class SomeResource {
  private Integer id;
  public SomeResource(@PathParam("ctxId") Integer id) {
    this.id = id;
  }

  // other methods
}

The mapping works fine with urls like http://the.host/ctx/132 but not with
the url http://the.host/ctx/
Is there a way to map the second url to the SomeResource class with a ctxId
with value null. I found two workarounds but I would like to know if there
is any easier way to have it working.

As for the workarounds, I could have the class mapped as @Path("ctx/") and
have two methods to take care of the requests with or with no ctxId or have
a basic class annotated with @Path("ctx/{ctxid}") and a subclass annotated
with @Path("ctx/") as it they share the same logic.