Add support for list value resolution from YAML block-style in Environment.getProperty() #35204
+126
−12
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.
Overview
This PR enables
Environment.getProperty()
to retrieve list values defined using YAML block-style notation, aligning its behavior with the already-supported inline style.Previously, this method supported only inline list syntax (
key: i,like,fish
) but failed when the YAML used block-style notation:As a result, calling:
would return
null
for block-style YAML. The issue is tracked in GitHub issue #35179.Spring’s Environment.getProperty() currently supports retrieving List values only when defined as a comma-separated string. YAML block-style list definitions, which are semantically equivalent, are ignored.
✅ YAML Supported (Inline):
This works as expected:
❌ YAML Not Supported (Block-style):
This returns
null
for the same code:The Solution
This PR enhances property resolution logic to support indexed keys such as:
This format corresponds to block-style YAML and is now properly aggregated into a List when calling:
Internally,
PropertySource#getProperty()
is updated to collect indexed entries into a list when a direct match is not found.Test Coverage
This fix is verified by the following test cases:
These tests ensure list values can be resolved from indexed keys when using Environment.getProperty().
Related Issue