How to merge multiple path parameters into one object

337 Views Asked by At

I have a route that looks like this:

/foobar/123/2

And I would like to use all three parameters to get a single object so that I can use something like this:

@Path("/{type}/{id}/{version}")
public Response getEntity(Entity entity);

Instead of:

@Path("/{type}/{id}/{version}")
public Response getEntity(@PathParam("type") Type type, @PathParam("id") Long entityId, @PathParam("version") Long version);

ParamConverter looks promising, however it can only handle a single String not three. Anything else I could try?

1

There are 1 best solutions below

0
On

I believe you are out of luck.

From JSR-000339 "Java[TM] API for RESTful Web Services 2.0 Final Release for evaluation "

the following types are supported

  1. Types for which a ParamConverter is available via a registered ParamConverterProvider. See Javadoc for these classes for more information.
  2. Primitive types
  3. Types that have a constructor that accepts a single String argument.
  4. Types that have a static method named valueOf or fromString with a single String argument that return an instance of the type. If both methods are present then valueOf MUST be used unless the type is an enum in which case fromString MUST be used.
  5. List, Set, or SortedSet, where T satisfies 3 or 4 above