11

So I'm having a controller method like this:

@RequestMapping(value = "/stuff, method = GET)
public StuffDTO getStuff(
        @RequestParam(value = "stuffIds") List<Integer> ids) {

I know I can provide a default value like this:

@RequestParam(value = "1,2,3")

But how do I set default value to an empty list, not to deal with null lists inside the endpoint implementation?

0

1 Answer 1

25

Just provide an empty string as a default value, no need for anything like [] etc.

@RequestMapping(value = "/stuff, method = GET)
public StuffDTO getStuff(
        @RequestParam(value = "stuffIds", defaultValue = "") List<Integer> ids) {
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.