Fix: FlatFileItemWriterBuilder - Ensure names() is respected for RecordFieldExtractor #4936
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.
Description
When using FlatFileItemWriterBuilder with Java Record types, specifying .names() is currently required, but RecordFieldExtractor ignores those names due to a missing .setNames() call. This causes all record components to be extracted regardless of the .names() setting, leading to unexpected behavior.
This patch fixes the issue by invoking .setNames() on RecordFieldExtractor when names are specified, aligning its behavior with BeanWrapperFieldExtractor used for non-record types.
No breaking changes are introduced.
Changes
Added .setNames() call on newly created RecordFieldExtractor if names are provided.
Maintains consistency and backward compatibility in builder API.
Motivation
Enables partial field extraction from Java Records via .names() method, matching the behavior for Java Beans.
Resolves a long-standing inconsistency and confusion reported by users and educators.
Additional Notes
Powerd by KILL-9 💀
Related Issue
This PR addresses issue #4935