Colby
Colby

Reputation: 313

Override @QueryParam annotation to trim whitespaces

Currently I'm working with Dropwizard and want to trim whitespaces from query parameters that are passed in, that match a specific key (in my case, query). I couldn't find documentation on how to do this.

The closest solution I've found, apart from manually trimming the whitespace, is to create a new annotation, however I'm trying to avoid changing dozens of endpoints, and would rather override the base annotation to apply the change.

Upvotes: 1

Views: 347

Answers (1)

LiorH
LiorH

Reputation: 18824

You could write a jetty servlet filter to modify that query param, see this thread for an example: https://stackoverflow.com/a/1422202/52954

Then register that filter:

environment.servlets().addFilter("Custom-Filter-Name", new MyCustomFilter());

Upvotes: 1

Related Questions