Q:

Read a csv file using FlatFileItemReader, throwing an exception when encountering an empty column

When using the FlatFileItemReader to read a csv file, a column mapping type is Int, but this column is null in the csv file (eg:6321517,Jack, 1,, . The last two columns are empty).
An exception(java.lang.NumberFormatException: Unparseable number) is thrown when parsing a file 
csv
CUSTR_NBR,SUR_NAME,CHECK_FLAG,RESN_CODE
6321517,Jack,1,,

The first line of data (CUSTR_NBR, SUR_NAME, CHECK_FLAG, RESN_CODE) is parsed at first, so I set .SetLinesToSkip(1). However, the corresponding "CHECK_FLAG" and "RESN_CODE" cannot be performed normally if the null value is parsed. I believe there is a corresponding configuration item. I looked at the documentation for springbatch and couldn't find any related configuration items.
csvItemReader
    @Bean
    @StepScope
    public FlatFileItemReader<InfoDTO> csvItemReader() {
        FlatFileItemReader<InfoDTO> csvItemReader = new FlatFileItemReader<>();
        csvItemReader.setResource(new ClassPathResource("data/charge-off.csv"));
        csvItemReader.setLinesToSkip(1);

        DelimitedLineTokenizer tokenizer=new DelimitedLineTokenizer();
        String[] tokens = new String[]{"CUSTR_NBR","SUR_NAME","CHECK_FLAG","RESN_CODE","EMPNO"};
        tokenizer.setNames(tokens);
        DefaultLineMapper<InfoDTO> lineMapper=new DefaultLineMapper<InfoDTO>();
        lineMapper.setLineTokenizer(tokenizer);
        lineMapper.setFieldSetMapper(new InfoFileMapper());
        lineMapper.afterPropertiesSet();
        csvItemReader.setLineMapper(lineMapper);

        return csvItemReader;
    }

mapper
    public class InfoFileMapper implements FieldSetMapper<ChargeOffBatchDTO> {
        @Override
        public InfoDTO mapFieldSet(FieldSet fieldSet) throws BindException {

            if(fieldSet == null){
                return null;
            }

            return new InfoDTO(
                fieldSet.readString("CUSTR_NBR"),
                fieldSet.readString("SUR_NAME"),
                fieldSet.readString("CHECK_FLAG"),
                fieldSet.readInt("RESN_CODE"),
                fieldSet.readInt("EMPNO")
            );
        }
    }

I need to map the null column to a value of 0. How to configure？

A:

I've not worked with Spring Batch, but looking at the FieldSet Interface specification, there seem to be some alternative of ways which you could achieve what you want. 
The Spring Batch reference does however mention some fault tolerance, specifically around throwing of exceptions, when a value does not exist. In order to disable this you need to set the strict to false
tokenizer.setStrict(false);

Otherwise you could simply try some old fashion alternatives, such as instead of trying to read the value directly into an int, just read it into a String and then validate that String before casting it to an int
String empNo = fieldSet.readString("EMPNO");
if ((empNo == null) || (empNo.equals(""))) {
  empNo = "0";
}
int i = Integer.valueOf(empNo);

You may still get a java.lang.NumberFormatException if the field is not empty and not a String, so personally I would just solve the problem by handling the exception:
int myEmp = 0;
try {
  myEmp = fieldSet.readInt("EMPNO");
} catch (NumberFormatException nfe) {
  myEmp = 0;
}

It's maybe not that eloquent, but it'll work and server the purpose. 

