samwell
samwell

Reputation: 2797

How do I skip/delete an item in the ItemProcessor?

I want to be able to delete an item while processing it if it fits a specific logic. For example, if the item doesn't contain a value I'm looking for, I don't want to that item to be written out to the file.

I'm currently using a class which implements ItemProcessor<T,T>.

Do I just return null?

Upvotes: 10

Views: 10075

Answers (1)

Srinivas Kasarla
Srinivas Kasarla

Reputation: 131

Return null from the processor like below.

public class ExceptionRecordValidator implements 
        ItemProcessor<yourDTO, yourDTO>{
@Override
public yourDTO process(
        yourDTOitem) throws Exception {
     if(your requested value found){
         return yourDTO ;
     }else{
         return null;
     }
  }
}

Upvotes: 12

Related Questions