質問

I am new to Spring Batch. Actually I am trying to validate the data in writer. So here I got the Subrogation (pojo class) from the processor, now I have to check it for validation -- if that object is already present in MAP than don't return that value to File; else return that data.

So here when I return null in if, it prints null in the output file.

Actually I want to skip that record from the file to remove duplicates.

Aggregate Method:

@Override
public String aggregate(Subrogration subrogration) {

    StringBuilder result = new StringBuilder();

    //StringBuffer sb = new StringBuffer();

    System.out.println("inside aggregator");
        result.append(subrogration.toString());

        logger.info("Subrogration result" + subrogration.toString());
        if(SubrogrationFileTransferTasklet.map.containsKey(subrogration.getGRP_NBR()+subrogration.getSECT_NBR())){
            System.out.println("douplicate value");
            return null;
        }
        else{
                    return result.toString();
        }

}

and the file output is

9970150000050
997500150000050
900250000050
99865400001000.0
9980250000100
9986520000100
9999050000100
null
01890001000.0
02076010001000.0
0207640001000.0
02076000001000.0
020760001000.0
02076000001000.0
020703010001000.0
02076880001000.0

I don't want that null in my file.

役に立ちましたか?

解決

To do this, you should be filtering in your ItemProcessor, not the LineAggregator. Your ItemProcessor should return null, which won't be written out. Filtering with the LineAggregator is too late in the process.

You can read more about filtering records using an ItemProcessor in the documentation (section 6.3.2) here: http://docs.spring.io/spring-batch/reference/html/readersAndWriters.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top