-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide mechanism to map request parameters to fields of DTO object #23094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It would also be nice to have the same functionality but also for headers (analogous to the |
Actually, there is a way of doing that: |
@imochurad that's cool! Although not as clean as your original proposal. However, I think it doesn't work for headers. |
This is now superseded by #23618. |
This is more of a feature request:
If I have a bunch of request parameters in my service method, I would like all of them to be grouped in a DTO object.
For instance, if I have a following method:
Disregard the names of the parameters. What is important here, that there could be plenty of those and some of them might be mutually exclusive. Since they might be mutually exclusive, I would like to validate the state of so-called
RequestParamsDTO
. Ideally, I would like to create a custom validator (using hibernate validator) and then annotate the argument of typeRequestParamsDTO
with the proper validation annotation.I know that there is a mechanism that even without the
@RequestParam
annotation spring will make its best to match arguments to the properties of a bean, in this case,RequestParamsDTO
object.But the problem lays in the naming of my request parameters:
some of them have dashes in the name, like
page-number
. I cannot create a field in myRequestParamsDTO
with that name for the obvious reasons.And it seems there is no mechanism to map those request parameters to the fields of the DTO.
It would be nice to have a mapping mechanism for such case or allow
@RequestParam
annotation on class fields.The text was updated successfully, but these errors were encountered: