spring-projects / spring-projects/spring-batch
Builders for FlatFileItemReader and FlatFileItemReaderWriter should allow using natural ordering of record
Nobody has claimed this yet.
- 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.DelimitedBuilderFlatFileItemReaderBuilder.FixedLengthBuilderFlatFileItemWriterBuilder.DelimitedBuilderFlatFileItemWriterBuilder.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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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