Skip to content

@RequestParam default value not set in certain cases [SPR-10180] #14813

Closed
@spring-projects-issues

Description

@spring-projects-issues

Michael Osipov opened SPR-10180 and commented

I have this @RequestMapping

@RequestMapping(value = "/{project:[A-Z0-9_+\\.\\(\\)=\\- ]+}", method = RequestMethod.GET, produces = {
    MediaType.APPLICATION_XML_VALUE, "application/json;charset=UTF-8" })
public ResponseEntity<Object> lookupProject(@PathVariable String project,
    @RequestParam(value = "attributes", required = false) String[] attributes,
    @RequestParam(value = "outputType", required = false, defaultValue = "HASH") OutputType outputType)

Where OutputType is an enum with the values HASH and ARRAY.

In the following edge cases:

GET /.../TEST-PROJECT?outputType HTTP/1.1
GET /.../TEST-PROJECT?outputType= HTTP/1.1

The outputType variable is not populated with the default value but a null is assigned. The RequestParamMethodArgumentResolver receives this as an empty string.

See the attached screenshot of the debugger.

If this cannot be reasonable fixed, add at least a paragraph to the docs that such edge cases exist.


Affects: 3.1.3, 3.2 GA

Attachments:

Referenced from: commits 3abe05c, 221562d

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: documentationA documentation tasktype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions