2

for @RequestParam there is the option to declare the variable as Optional<T> to find out if the parameter was set at all. Is there something similar for @RequestBody members?

For example take the following class used as a @RequestBody parameter in a patch endpoint. Is it possible to differentiate between a null name and no name at all? I'd like to only set the name to null, if the client explicitly sets the name to null (rather than leaving out the name).

public class UserPatchRequestBody {
    public String name
}
Superwayne
  • 1,146
  • 1
  • 12
  • 22

1 Answers1

1

You could do something like

@RequestParam(defaultValue = "empty", required = false) String name

So, if the client didn't place anything you would have "empty" (or whatever you want) instead of "null".

duppydodah
  • 165
  • 1
  • 3
  • 17