Convert elements of collection- and array-valued query method parameters#3506
Open
seonwooj0810 wants to merge 1 commit into
Open
Conversation
…ers. Query method parameters exposed through Spring Data REST were passed to the backing repository without element conversion when the raw value already was an instance of the declared target type (e.g. a `List`). As a result, a repeated request parameter such as `?colors=RED&colors=GREEN` reached an `in`-style query as a `List<String>` instead of a `List<Color>`, causing the persistence provider to fail. `ReflectionRepositoryInvoker` now also invokes conversion for array- and `Iterable`-typed parameters even when the value already matches the target type, so the raw elements get converted to the declared element type.
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.
Fixes #3502
Root cause
ReflectionRepositoryInvoker#prepareParametersskipped conversion whenever the resolved value already was an instance of the declared parameter type. For a collection- or array-valued parameter this is wrong: a repeated query parameter (e.g.?colors=RED&colors=GREEN) resolves to aList<String>, which is an instance of the targetList/Collection, soconvert(...)was never called and the rawStringelements were never converted to the declared element type (e.g. an enum). The unconvertedList<String>then reached thein-style query and the persistence provider failed. (As diagnosed by @antonioT90 in the issue, with a reproducer.)Change
For array- and
Iterable-typed parameters, conversion is now performed even when the value already matches the target type, so the elements are converted to the declared element type. Scalar parameters keep the previous fast-path (no redundant conversion).Tests
Added
ReflectionRepositoryInvokerUnitTests#convertsElementsOfCollectionValuedQueryParameter, which binds aList<String>to aCollection<Color>query parameter and asserts the repository receives converted enum values. It fails before the change (repository receives the rawStrings) and passes after.Verification done: (1) no in-flight PR — searched open PRs for
3502andReflectionRepositoryInvoker(only unrelated #3439); (2) no self-claim comments; assigneeodrotbohmis routine triage tracking (89 open issues assigned); (3) code-focused, touches only.java; (4) confirmed the pattern still present on currentmain; (6) issue is past triage (type: bug), so no triage gate. Ran./mvnw -o test -Dtest=ReflectionRepositoryInvokerUnitTests— 20/20 pass with the fix; the new test fails without it.