Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix string array decode #35533

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

Closed

Conversation

Copy link

@Prabal864 Prabal864 commented Sep 23, 2025

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 produce
a 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 module
demonstrating the correct way to decode JSON arrays into List<String> using
ParameterizedTypeReference.

Key points:

  1. Embedded Netty server for tests

    • The tests spin up a lightweight embedded Netty server on a dynamic port.
    • This ensures the tests are self-contained and do not rely on external services.
  2. Correct JSON decoding

    • bodyToMono(new ParameterizedTypeReference<List<String>>() {}) correctly converts
      the JSON array into a List<String>.
  3. Covers both empty and non-empty arrays

    • decodeNotEmptyList() → decodes ["hello", "world"] into a list of two strings.
    • decodeEmptyList() → decodes [] into an empty list.
  4. Assertions

    • Uses AssertJ assertThat() to verify the decoded lists exactly match expected values.

Benefits

  • Ensures WebClient correctly decodes JSON arrays into collections.
  • Provides a reproducible test case for this edge case in WebFlux.
  • Improves reliability for developers consuming JSON arrays in reactive applications.
  • Fully self-contained; can run in CI without external dependencies.

Test Instructions

  1. Run the tests locally:

    ./gradlew :spring-webflux:test --tests "org.springframework.web.reactive.function.client.StringArrayDecodeTests"

...on-empty lists
Signed-off-by: prabal864 <940pps@gmail.com>
...on-empty lists
Signed-off-by: prabal864 <940pps@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 23, 2025
Copy link
Contributor

This is expected behavior documented at https://docs.spring.io/spring-framework/reference/web/webflux/reactive-spring.html#webflux-codecs-jackson (note at the end of section).

@rstoyanchev rstoyanchev removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /