I realized that I can get the lineNumber value in MyObject by overriding DefaultLineMapper using my own LineMapper like this:
import org.springframework.batch.item.file.FlatFileParseException; import org.springframework.batch.item.file.LineMapper; import org.springframework.batch.item.file.transform.LineTokenizer; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; import my.model.MyObject; public class MyLineMapper<T> implements LineMapper<MyObject>, InitializingBean { private LineTokenizer tokenizer; private ResourceFieldSetMapper fieldSetMapper; public MyObject mapLine(String line, int lineNumber) throws Exception { try{ MyObject r = fieldSetMapper.mapFieldSet(tokenizer.tokenize(line));
Thank you for your help! Hope this works for someone!
Blessings!
source share