1

How to fail on invalid query parameter name with RESTEasy?

Consider a valid REST request like this one: /list?sort-by=date

Then, user makes this request: /list?sort_by=date

See that user replaced hyphen with underscore. It works, but it will ignore parameter and use default sorting (param not mandatory).

With Jackson, if a JSON with invalid member is sent it throws an Exception. I would like a similar behavior to query params (header params would be awesome too). Tested with @BeanParam, but apparently it doesn't use Jackson in this case.

RESTEasy version 3.15.1.

Claudio Weiler
  • 589
  • 2
  • 15

1 Answers1

0

You have to check that in your code. Query params are not in json in standard, you can do that with a class with string constructor. In fact "sort_by" is not bind to a method parameter, so it's ignored. If you want that "sort-by" to be mandatory you have to do that in your code :

Required @QueryParam in JAX-RS (and what to do in their absence)

Currently since RESTEasy is built on top of a Servlet, it does not distinguish between URI query strings or url form encoded parameters. Like PathParam, your parameter type can be an String, primitive, or class that has a String constructor or static valueOf() method.

https://docs.jboss.org/resteasy/docs/3.15.1.Final/userguide/html_single/#_QueryParam

Mr_Thorynque
  • 1,749
  • 1
  • 20
  • 31
  • "Query params are not in json in standard, you can do that with a class with string constructor": can you elaborate more on this? Also, 'required' isn't an option, it's not a mandatory param, as - poorly ;) - explained, it has a default value/behavior. – Claudio Weiler Aug 29 '22 at 20:26