I'm reading a csv file with FlatFileItemReader and using a FieldSetMapper to map it to a domain object.
In case the mapping fails, I would like to have the original line read by the FlatFileItemReader at my disposal so I could write it to another csv file.
My original idea was to use some listener to push the read string to StepContext and then a SkipListener to fetch the string to write it to another file. But I can't find a way to catch the original line read by the FlatFileItemReader.
Suggestions?
Implementing the onReadError(Exception) method of the ItemReadListener interface does exactly what you need.
public void onReadError(Exception e) {
if(e instanceof FlatFileParseException) {
FlatFileParseException ffpe = (FlatFileParseException) e;
ffpe.getLineNumber(); //The line number error occured
ffpe.getInput();//Text value of the unparsed line
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With