UriBuilder - Correct the treatment of Optional types.#25950
Closed
robinroos wants to merge 1 commit intospring-projects:masterfrom
Closed
UriBuilder - Correct the treatment of Optional types.#25950robinroos wants to merge 1 commit intospring-projects:masterfrom
robinroos wants to merge 1 commit intospring-projects:masterfrom
Conversation
This was referenced Oct 21, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is an alternative to #25925 and all the discussion on that PR remains relevant.
This PR is an improvement because:
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.