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.
Context / Problem
In Spring Framework 6 / WebFlux, using
WebClient
to decode a JSON array of strings(e.g., ["hello", "world"]) into a
List<String>
sometimes resulted in unexpected behavior:the JSON array was decoded as a single String containing the raw JSON ("["hello","world"]")
instead of a proper
List<String>
.This issue also occurs for empty arrays: decoding "[]" into a
List<String>
could producea list containing a single string "[]" rather than an empty list.
This behavior is confusing and can lead to subtle bugs when consuming JSON arrays
from reactive endpoints.
Solution
This PR adds self-contained reproducer tests to the
spring-webflux
moduledemonstrating the correct way to decode JSON arrays into
List<String>
usingParameterizedTypeReference
.Key points:
Embedded Netty server for tests
Correct JSON decoding
bodyToMono(new ParameterizedTypeReference<List<String>>() {})
correctly convertsthe JSON array into a
List<String>
.Covers both empty and non-empty arrays
decodeNotEmptyList()
→ decodes["hello", "world"]
into a list of two strings.decodeEmptyList()
→ decodes[]
into an empty list.Assertions
assertThat()
to verify the decoded lists exactly match expected values.Benefits
WebClient
correctly decodes JSON arrays into collections.Test Instructions
Run the tests locally:
./gradlew :spring-webflux:test --tests "org.springframework.web.reactive.function.client.StringArrayDecodeTests"