I found an answer similar to this question but it isn't working when posting JSON data. I have the following:
@ControllerAdvice
public class ControllerConfig {
@InitBinder
public void initBinder ( WebDataBinder binder ) {
StringTrimmerEditor stringtrimmer = new StringTrimmerEditor(true);
binder.registerCustomEditor(String.class, stringtrimmer);
}
}
I know that the code is being reached during binding via debugging but when I pass in data like:
{ "companyId": " ABC "}
ABC
isn't actually being trimmed during binding. My guess is that this only works with request params and not raw JSON bodies but not sure about that. If that is the case, is there something I can do that is similar?