users@jersey.java.net

[Jersey] Optional PathParam is it possible?

From: Dário Abdulrehman <dario.rehman_at_gmail.com>
Date: Wed, 17 Feb 2010 23:40:25 +0000

Given the following resource method:

@GET @Path("tfs/{tf : .*}/genes/{gene : .*}/evidence_codes/{evidence_code:
.*}")
public Response doGet(@Context Request req,
            @PathParam("tf") List<PathSegment> tfs, @PathParam("gene")
List<PathSegment> genes,
            @PathParam("evidence_code") List<PathSegment> ecs,


I would like to make each one of the PathSegments optional (tfs/, genes/ and
evidence_codes/), however like it is now, if I don't provide for instance,
any genes,
I still have to GET the resource like:

GET /resource/tfs/tf1/tf2/genes//evidence_codes/ec1

Notice the double slash after "genes".

It would be nicer if I could just do:

 GET /resource/tfs/tf1/tf2/evidence_codes/ec1

instead.

Is there any way to accomplish this?

Thanks.