use of org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper in project microservices by pwillhan.
the class ContactBatchJobConfiguration method reader.
@Bean
public ItemReader<Contact> reader() {
FlatFileItemReader<Contact> reader = new FlatFileItemReader<>();
reader.setResource(new ClassPathResource("data.csv"));
reader.setLineMapper(new DefaultLineMapper<Contact>() {
{
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames(new String[] { "firstName", "lastName", "email" });
}
});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Contact>() {
{
setTargetType(Contact.class);
}
});
}
});
return reader;
}
use of org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper in project microservices by pwillhan.
the class BatchConfiguration method flatFileItemReader.
@Bean
@StepScope
FlatFileItemReader<Person> flatFileItemReader(@Value("#{jobParameters[file]}") File file) {
FlatFileItemReader<Person> r = new FlatFileItemReader<>();
r.setResource(new FileSystemResource(file));
r.setLineMapper(new DefaultLineMapper<Person>() {
{
this.setLineTokenizer(new DelimitedLineTokenizer(",") {
{
this.setNames(new String[] { "first", "last", "email" });
}
});
this.setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
{
this.setTargetType(Person.class);
}
});
}
});
return r;
}
Aggregations