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

FlatFileItemWriterBuilder - RecordFieldExtractor does not honor names() for Java Record types #4935

Closed as duplicate of#4916
Labels
@DevSeongmin

Description

Bug description
When using FlatFileItemWriterBuilder with Java Record types, specifying partial fields via .names() does not work as expected. Internally, the RecordFieldExtractor is created but the .setNames() method is not called, causing the extractor to output all record fields instead of only the specified subset.

Environment

  • Spring Batch version: 6.x (e.g., 6.0.0-M1)
  • Java version: 17 or higher
  • Build tool: Maven or Gradle
  • Database: In-memory database (H2) or none for this test
  • Operating system: Any

Steps to reproduce
Define a Java Record class, e.g.:

public record UserInfo(
 String username,
 String email,
 int age,
 String phoneNumber
) {}

Create and configure the writer with .sourceType(UserInfo.class) and partial fields with .names("username", "phoneNumber").
Write items using this writer and verify that the output file contains all fields instead of only the specified ones.

Expected behavior
Only the fields specified in .names() should be extracted and written to the output file, excluding all others.

Minimal Complete Reproducible example

@Bean
@StepScope
public FlatFileItemWriter<UserInfo> userInfoWriter(
 @Value("#{jobParameters['outputDir']}") String outputDir) {
 return new FlatFileItemWriterBuilder<UserInfo>()
 .name("userInfoWriter")
 .resource(new FileSystemResource(outputDir + "/user_infos.csv"))
 .delimited()
 .delimiter(",")
 .sourceType(UserInfo.class)
 .names("username", "phoneNumber")
 .build();
}

// After writing, the output CSV still contains all fields instead of only username and phoneNumber.

Expected.

Alice Johnson,555-123-4567
Bob Smith,555-987-6543
Carol Williams,555-234-5678
David Brown,555-345-6789
Eve Davis,555-456-7890

Result.

Alice Johnson,alice.johnson@example.com,28,555-123-4567
Bob Smith,bob.smith@example.com,35,555-987-6543
Carol Williams,carol.williams@example.com,42,555-234-5678
David Brown,david.brown@example.com,30,555-345-6789
Eve Davis,eve.davis@example.com,27,555-456-7890

Additional Notes
Powerd by KILL-9 💀

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

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