spring-projects / spring-projects/spring-batch

Builders for FlatFileItemReader and FlatFileItemReaderWriter should allow using natural ordering of record

Open
#5,017 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: feature
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

Expected Behavior

FlatFileItemReader and FlatFileItemReaderWriter builders allows to customize the field names of the target/source bean to write/read via :

  • FlatFileItemReaderBuilder.DelimitedBuilder
  • FlatFileItemReaderBuilder.FixedLengthBuilder
  • FlatFileItemWriterBuilder.DelimitedBuilder
  • FlatFileItemWriterBuilder.FormattedBuilder

As it is a common behavior to create a dedicated record bean for this, it could be useful to allow to use the natural ordering of record's bean instead of manually specify fields name as string.

Example :

FlatFileItemReader<MyRecord> reader = new FlatFileItemReaderBuilder<MyRecord>()
                .targetType(MyRecord.class)
                .resource(inFile)
                .delimited()
                .delimiter(",")
                .quoteCharacter('\"')
                .withRecordFieldOrdering()
                .build();

Context

Currently, you can workaround this by extracting the fields and pass it to names(...) :

String[] fieldsName = Arrays.stream(MyRecord.class.getRecordComponents())
                .map(RecordComponent::getName).toArray(String[]::new);

FlatFileItemReader<MyRecord> reader = new FlatFileItemReaderBuilder<MyRecord>()
                .targetType(MyRecord.class)
                .resource(inFile)
                .linesToSkip(1)
                .delimited()
                .delimiter(",")
                .quoteCharacter('\"')
                .names(fieldsName)
                .build();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the four named builder entry points: FlatFileItemReaderBuilder.DelimitedBuilder, FixedLengthBuilder, and the corresponding FlatFileItemWriterBuilder builders. Review how targetType and names are handled, then verify that a withRecordFieldOrdering option can derive record component order for reading and writing. Done means each listed builder supports natural ordering with coverage for the requested record use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.