0

I have following REST controller in Java Spring Application:

@RequestMapping(
     value = "/api/getApplication/{me_userId}", 
     method = RequestMethod.GET, 
     produces = MediaType.APPLICATION_JSON_VALUE)
public Object getApplication(
        @PathVariable String userId,
        @RequestParam(value="fieldNames[]", required = false) String[] fieldNames) {

            if (fieldNames != null) {
                for (String fieldName : fieldNames)
                    System.out.println(fieldName);
            }

            ...
            return null;
}

So I can not succeed in simulating API call from DHC REST of POSTMAN what will pass that fieldNames[].

Does anyone know how to do it?

1
  • There is a typo: @PathVariable String should be - me_userId Commented Jan 22, 2016 at 9:47

1 Answer 1

1

First of all, your current method does not work because your @PathVariable is wrong. In your @RequestMapping you have the following placeholder in your path: {me_userId}, which means that it will be mapped to a path variable with that name.

However, the only @PathVariable you have is nameless, which means it will use the name of the parameter (userId) in stead.

So before you try to execute your request, you have to change your @RequestMapping into:

@RequestMapping(
    value = "/api/getApplication/{userId}", // <-- it's now {userId}
    method = RequestMethod.GET, 
    produces = MediaType.APPLICATION_JSON_VALUE)

Then, if you run the application, you can kinda choose how you want to pass your parameters. Both the following will work:

?fieldNames[]=test,test2

Or:

?fieldNames[]=test&fieldNames[]=test2

Both these results should print the desired results.

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

2 Comments

Yeah, sorry, it is a typo, it should be me_userId in a @PathVariable String
And, yes, Thank you very much your solutions work, so we basically have to append the array with variables to URL. That is fine, it works for me!

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.