Results 1 to 4 of 4

Thread: different fieldsetMapper for first line

  1. #1
    Join Date
    Jun 2007
    Posts
    2

    Default 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?

  2. #2

    Default

    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.

  3. #3
    Join Date
    Jun 2007
    Posts
    2

    Default

    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.

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •