(I'm using Spring 4.0.x)
Lets say I've got the following controller method defined:
@RequestMapping(value = "/endpoint", method = RequestMethod.POST)
public ResponseObject postNewRequest(@Valid @RequestBody RequestObject request) {
return randomService.processRequest(request);
}
RequestObject
is basically a JSON payload, which Jacksons ObjectMapper
maps to given DTO.
What is the cleanest approach for me modify object which Jackson
serializes, before validation kicks in and before it gets passed down to the service?
Example use case: I want to be nice and if user provides me with a value which I can safely trim, I want to do this here, instead of worrying about this in the service?
Bonus question: is it possible for this to be specified per RequestObject
class, not per controller method?
Thank you very much for any help in here and spending time reading this question.