I checkout this project from spring: https://github.com/spring-guides/gs-batch-processing
Source: https://spring.io/guides/gs/batch-processing/
I replace the ',' with 'tab' in 'sample-data.csv:
Jill Doe
Joe Doe
Justin Doe
Jane Doe
John Doe
Then I add the new Delimiter to the reader:
@Bean
public FlatFileItemReader<Person> reader() {
return new FlatFileItemReaderBuilder<Person>()
.name("personItemReader")
.resource(new ClassPathResource("sample-data.csv"))
.delimited()
.delimiter(DelimitedLineTokenizer.DELIMITER_TAB) // NEW DELIMITER
.names(new String[]{"firstName", "lastName"})
.fieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
setTargetType(Person.class);
}})
.build();
}
When I launch I get this error:
Caused by: org.springframework.batch.item.file.transform.IncorrectTokenCountException: Incorrect number of tokens found in record: expected 2 actual 1
at org.springframework.batch.item.file.transform.AbstractLineTokenizer.tokenize(AbstractLineTokenizer.java:142) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:43) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:180) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
... 50 common frames omitted
I have tried with '@' delimiter -> it works. For some reason, I can't make it work with the tab delimiter...
Of course in my real project, I have an input file with 'tab' separators...
Any solution here?
Joe Doe
maybe the tokenizer complains about that?