Skip to content

FlatFileItemReaderBuilder does not overrule comment prefixes in returned FlatFileItemReader [BATCH-2837] #779

Closed
@spring-projects-issues

Description

@spring-projects-issues

Benne Otten opened BATCH-2837 and commented

When using the FlatFileItemReaderBuilder to build your reader, it is not possible to overrule the comment prefixes defaults. Consider the following example 

@Bean
public FlatFileItemReader<FieldSet> itemReader() {
    return new FlatFileItemReaderBuilder<FieldSet>()
            .name("itemReader")
            .resource(new ClassPathResource("file.xml"))
            .lineMapper(linemapper())
            .comments(new String[]{})
            .build();
}

In this example the default comment prefix of '#' is still set in the returned FlatFileItemReader. It took me a while to figure this out.

It's quite easy to circumvent this bug, like the next example, but it kinda defeats the purpose of using a builder.

@Bean
public FlatFileItemReader<FieldSet> itemReader() {
    FlatFileItemReader<FieldSet> itemReader = new FlatFileItemReaderBuilder<FieldSet>()
            .name("itemReader")
            .resource(new ClassPathResource("file.xml"))
            .lineMapper(linemapper())
            .build();
    itemReader.setComments(new String[]{});
    return itemReader;
}

Maybe it's intentional to always set a comment prefix of '#', but I did not expect this. I'm using the reader to read some ancient file that does not adhere to modern guidelines.


Referenced from: pull request #733

Backported to: 4.3.0.M1, 4.2.1, 4.1.3, 4.0.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions