Imagine a Menu.java pojo with 3 fields: id, name and telephone.
I'm using Spring Batch 3. My processor returns me a List. And I want to write on a file these values of each object of the list.
If Menu wasn't a list, this would be my writer class:
@Bean(name="MyWriter")
@SphynxBatchStepScope
public FlatFileItemWriter<Menu> myWriter() String fileOutputName) {
FlatFileItemWriter<Menu> writer = new FlatFileItemWriter<Menu>();
writer.setResource(new FileSystemResource("test.txt")));
DelimitedLineAggregator<Menu> delLineAgg = new DelimitedLineAggregator<Menu>();
delLineAgg.setDelimiter(" ");
BeanWrapperFieldExtractor<Menu> fieldExtractor = new BeanWrapperFieldExtractor<Menu>();
fieldExtractor.setNames(new String[] {"id", "name", "telephone"});
delLineAgg.setFieldExtractor(fieldExtractor);
writer.setLineAggregator(delLineAgg);
writer.setHeaderCallback(header());
writer.setFooterCallback(footer());
writer.setEncoding("UTF-8");
return writer;
}
But if I want to covert this class to works with a List how can I do it?
I can't find any solution. Only this:
Using an ItemWriter with List of Lists
But I don't see how implement this. For example, where and how call to setDelegate method. Or when I need to put my "id", "name", "telephone" sequence.
Please, does anybody knows a code example with a custom Writer with List?
Thanks in advance