Skip to content
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

UriBuilder - Correct the treatment of Optional types. #25950

Conversation

robinroos
Copy link
Contributor

This PR is an alternative to #25925 and all the discussion on that PR remains relevant.

This PR is an improvement because:

  1. it retains the existing public API without alteration, and
  2. it applies a consistent treatment even when an Optional is included amongst a list of arguments (varargs).

I have taken the liberty of updating the interface documentation.

It previously stated

If no values are given, the resulting URI will contain the query parameter name only, ...

I have complimented this by stating that

If the only values given are {@code Optional} instances for which {@code isPresent()} returns {@code false} then the query parameter name will not be added.

My justification is that calling the method with an explicit null (no parameters are given) is deliberately different from calling the method with one or more instances of Optional.empty.

Furthermore, please note that the current implementation is deficient when invoked with one or more Optionals as arguments, in that the text written to the URL is the .toString() of the Optional instance and not the .toString() of the value it contains; invoke queryParam("name", Optional.of("value")) and what is added to the URL is "?name=Optional[value]", not the expected "?name=value".

Something needs to be done, and I believe this PR (which omits the queryParam entirely if all passed values are Optional.empty) is the correct solution.

@robinroos robinroos changed the title Correct the treatment of Optional types. UriBuilder - Correct the treatment of Optional types. Oct 21, 2020
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 21, 2020
@rstoyanchev rstoyanchev added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants