Ninja Framework JSR303Validation in Filter

285 views Asked by At

I'm working on a Ninja JSON-based application in which I am implementing @JSR303Validation annotations across multiple controller methods. I'm currently checking validations in the controllers themselves by passing in the Validation object and calling validation.hasBeanViolations() to see if there are failures. If there are, I'm returning a failing Result to the client.

Rather than doing this in the controller, I would like to validate requests using a Filter. However, I'm at a loss as to how to go about doing this? Could somebody help? As far as I can tell, you can't pass validations to a filter as a parameter, and the context.getValidation() object does not seem to be catching any validation failures.

1

There are 1 answers

0
Ra_ On BEST ANSWER

That's currently not possible using a Filter (as of Ninja 4.0.x). However, you can implement it yourself. That would work roughly the following way:

That's not too complicated. But it's not as automagic as annotating methods in the controllers.