Jan 28th, 2008, 12:47 AM
different fieldsetMapper for first line
I am using spring batch for an application to import payment via an unattended upload. The first line of this payments file is an header that describes the file. After the import I have to check that the number of imported payment is the same as the number in the header. Is it possible with the framework to use a different fieldsetMapper for the first line than for the other lines?
Jan 28th, 2008, 02:46 AM
You'll probably want to implement a custom ItemReader for this. The sample OrderItemReader should be a good starting point (reads file with header and footer).
Simple header support is also included in the SimpleFlatFileItemReader which allows you to skip the header or use it to setup column names for fieldSet.
Jan 28th, 2008, 02:57 AM
i saw the possibility to skip the header, but i contains information i need in the process. So skipping it is no option. I shall have a look at the adviced sample.
Jan 28th, 2008, 03:30 AM
I'm not sure that you really need to implement a new ItemReader. The FieldSetMapper you implement should probably be composite, meaning that it contains two mappers, one for the header, and another for everything else. Spring Batch has a FieldSetMapper that will use the first column in the row to determine which mapper it should be handed to. You could also write a custom one that just uses a different mapper for the first line, but you need to be very careful about how you handle that state, especially in a restart scenario.