Skip to content

Provide mechanism to map request parameters to fields of DTO object #23094

Closed
@imochurad

Description

@imochurad

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:

@GetMaping
public ResponseEntity<?> listEntities(
        @RequestParam(value = "page-number", defaultValue = "0") @Min(0) Integer pageNumber,
        @RequestParam(value = "page-size", defaultValue = "100") @Min(1) Integer pageSize, ... )

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 type RequestParamsDTO 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 my RequestParamsDTO 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions