Announcement Announcement Module
Collapse
No announcement yet.
different fieldsetMapper for first line Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment

        Working...
        X