简体   繁体   中英

Skipping bad rows in file with itemProcessor in spring batch

20180627;PM;ABC;0029;BYX;Technology Inc;;DUMMY;OK;33900;34.3;1162770;CT;;;;;;
;;;;;;;;;;;;;;;;;; //bad line
;;;;;;;;;;;;;;;;;;  //bad line
;;;;;;;;;;;;;;;;;;  //bad line 

Is there a way I can skip the bad lines with no data in my MyProcessor :

public class MyProcessor implements ItemProcessor<Row, Price> {

    @Override
    public Price process(final Row row) throws Exception {

        if (row == null) {

        }

        //Values for lines in file
        Price scp = new Price();

      //set values

        return scp;
    }

}   

The values of the Row object are nulls. I have seen examples with blank lines, but here I am dealing with colons which is actually the delimiter.

Do I have to check for validity of certain fields and prevent object creation and settings ? Is there a better way?

Use a PatternMatchingCompositeLineMapper to separate valid lines from invalid ones and with a custom FieldSetMapper map invalid lines to an object called InvalidLine (just an example).
In processing phase use a CompositeItemProcessor to pass InvalidLine objects through a custom ItemProcessor and do what do you prefer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM