users@jersey.java.net

Re: [Jersey] Null as pathparam

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 2 Aug 2010 11:47:40 +0200

Hi,

You may have to use the workarounds.

Or using the following:

@Path("/ctx/{ctxId: [^/]*}")

and change the Integer to a String, check for an empty value or
otherwise convert to an Integer. Although it is not so pretty you
could write your own Integer holder type to do that work.

Currently we do not support @DefaultValue with @PathParam, which even
if we did would not result in a null value.

Paul.


On Jul 31, 2010, at 11:54 PM, Yoryos wrote:

> 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.