Announcement Announcement Module
No announcement yet.
Pass data from FileReader to RecordMapper Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pass data from FileReader to RecordMapper


    I have a problem passing data from a FileReader to a RecordMapper. Here is the description of my problem:

    I have a file which contains some comments at the beginning followed by header which describes the format of the records in the file (all recrods are of the same format). I have already implemented the FileReader which works fine. However now I want to implement the RecordMapper which should return objects of type Map which represent one record (per line). The Map should have the field-name as the key and the field value as the column value. (similar to a csv file).
    The problem I have is I can't figure out how I can pass the header information to the RecordMapper which then uses this info to create the Map objects.

    I already tried with an execution context but could not figure out how to access the execution context from the RecordMapper. Any suggestions/examples/hints etc. would be really appreciated.


    P.S.: As mentioned earlier - reading a csv file must be similar to what I'm trying.

  • #2
    First, I'm going to assume that by "FileReader" you mean "FlatFileItemReader" and by "RecordMapper" you mean "LineMapper".

    To access the ExecutionContext from any class, you can implement a BeforeStep method like this:
        private StepExecution stepExecution;
        private T mapLine(String line, int lineNumber) throws Exception {
            ExecutionContext stepContext = this.stepExecution.getExecutionContext();
            // ...
        public void saveStepExecution(StepExecution stepExecution) {
            this.stepExecution = stepExecution;
    Of course, you will have to register this class as a listener on the step.