posted 3 years ago
Ok, done some tests: please consider following code:
What makes the difference is that the first method is handled directly by Spring, which return a quite complex response with a full trace of the validation error. Using a service, when validation isn't satisfied an exception is thrown, which is in turn returned to the caller as a much simpler JSON response.
So, which approach is best ? I'd vote for putting the validation logic in a @Service, if present: this way, one could catch the exception and handle it the way he prefers.