Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:16:35+00:00 2026-06-05T13:16:35+00:00

JAX-RS/Jersey allows URL path elements to be converted to Java method arguments using @PathParam

  • 0

JAX-RS/Jersey allows URL path elements to be converted to Java method arguments using @PathParam annotations.

Is there a way to convert an unknown number of path elements into arguments to a vararg Java method? I. e. /foo/bar/x/y/z should go to method: foo(@PathParam(...) String [] params) { ... } where params[0] is x, params[1] is y and params[2] is z

Can I do this in Jersey/JAX-RS or some convenient way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:16:36+00:00Added an answer on June 5, 2026 at 1:16 pm

    Not sure if this is exactly what you were looking for but you could do something like this.

    @Path("/foo/bar/{other: .*}
    public Response foo(@PathParam("other") VariableStrings vstrings) {
       String[] splitPath = vstrings.getSplitPath();
       ...
    }
    

    Where VariableStrings is a class that you define.

    public class VariableStrings {
    
       private String[] splitPath;
    
       public VariableStrings(String unparsedPath) {
         splitPath = unparsedPath.split("/");
       }
    }
    

    Note, I haven’t checked this code, as it’s only intended to give you an idea.
    This works because VariableStrings can be injected due to their constructor
    which only takes a String.

    Check out the docs.

    Finally, as an alternative to using the @PathParam annotation to inject a VariableString
    you could instead wrap this logic into your own custom Jersey Provider. This provider would inject a “VariableStrings” more or less the same manner as above, but it might look a bit cleaner. No need for a PathParam annotation.

    Coda Hale gives a good overview.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a RESTful web service in java using JAX-RS and jersey and
I'm using Google Guice with Jersey (jax-rs). Following method throws an JAXB-Exception (JAXB can't
Using Jersey 1.7, JAX-WS 2.2.3, Tomcat 6.0.30 and the following method declaration prevents Jersey
Is there a way to use this parameter style: /products/123;456;789 in JAX-RS with Jersey?
i have a java web application, using Spring, Jersey (jax-rs) and Hibernate. It runs
I have a number of classes exposed as JAX-RS request handlers, using javax.ws.rs.Path annotations.
I'm using Jersey (jax-rs), to build a REST rich application. Everything is great, but
I am using the JAXB that is part of the Jersey JAX-RS. When I
I am querying a database for a web service using the Jersey JAX-RS. I
How do I set the xml namespace when using Jersey, jaxb & jax-rs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.