7

I'm struggling to believe that my need to trim leading and trailing whitespace from request parameters is not a common requirement, and yet I can't seem to find anyone who has a good answer to solving it.

Surely there is some simple way to configure, say, the Spring WebDataBinder to trim all whitespace from parameter values before mapping them to a target object?

I'd be really keen to know how other people have tackled this.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
DrewEaster
  • 3,316
  • 3
  • 35
  • 39

1 Answers1

6

You can try registering a custom PropertyEditor in the WebDataBinder

 registerCustomEditor(String.class, propertyEditor)

Either create one or use the StringTrimmerEditor, and instantiate it with a set of whitespaces.

Jacob Mattison
  • 50,258
  • 9
  • 107
  • 126
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140