spring-projects / spring-projects/spring-batch

BeanWrapperFieldSetMapper ignores FieldSet#read* methods

Open
#3,628 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Using Spring Batch version 2.2.2.
Want to use a FlatFileItemReader to parse a simple CSV file. Numbers inside CSV have commas as decimal separators.
Building the reader as follows:

@Bean
public FlatFileItemReader<MyTarget> reader() {
    DefaultFieldSetFactory fieldSetFactory = new DefaultFieldSetFactory();
    fieldSetFactory.setNumberFormat(NumberFormat.getInstance(Locale.getDefault()));

    return new FlatFileItemReaderBuilder<MyTarget>()
            .name("myReader")
            .resource(new FileSystemResource("a/filename"))
            .delimited()
            .delimiter(";")
            .fieldSetFactory(fieldSetFactory)
            .names(new String[] { "field1", "field2", "field3" })
            .targetType(MyTarget.class)
            .build();
}

Checked that fieldSetFactory has the right decimal separators.

This ItemReader works well with dot-separated decimal number, but fails to work with commas as decimal separators. Tested with fully custom FieldSet but DefaultFieldSet from DefaultFieldSetFactory is also affected.
The appropriate read*methods (readFloat for instance) are never called. Instead BeanWrapperFieldSetMapper converts the given input by using ConversionService and PropertyEditors. This might be a good idea in general but leads to ignorance of FieldSet's read* methods and thus makes it impossible to configure NumberFormats and DateFormats (among other things).

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 with BeanWrapperFieldSetMapper and trace how it maps values instead of calling FieldSet#read* methods; compare that path with DefaultFieldSet and the configured NumberFormat. Reproduce the locale-specific decimal case from the issue and add regression coverage showing the intended FieldSet conversions are honored.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, data-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.