0

I'm creating a endpoint (using Jersey annotations) that receives a list of Strings as it's parameter. The strings need to contain a key and a value. So on the url it would look something like

?params=key1=value1&params=key2=value2&params.... 

Two questions:

  • I'm not sure if the above example would work, I assume you would have to encode the = sign between key and value. Is that correct?
  • Is there a better or more standard way to approach this?

Obviously the most standard way would be to have the RHS be the key and the LHS of the equal sign would be the value. The problem is I don't want to define every possible key value pair in my method signature. I want to accept a general list of keys and values and let the user pass in the pairs that are relevant to their query.

So far I've tried several google queries but haven't found an answer:

1 Answer 1

1

Yes. Jersey can handle it even = between key and value is not encoded.If query parameter is params=key1=value1&params=key2=value2 , the params list below will be [key1=value1, key2=value2]

@GET
public Response q34211549(@QueryParam("params") List<String> params) {
    //parse params list and convert it into key and value
}

You can also consider to create a ParamConverter to let Jersey to do this conversion for you.

Reference

Sign up to request clarification or add additional context in comments.

1 Comment

This answers my first question. Do you have any insight on my second question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.