Making a item reader to return a list instead single object - Spring batch

spring-batch

Solution

take a look at the official spring batch documentation for itemReader

public interface ItemReader<T> {

    T read() throws Exception, UnexpectedInputException, ParseException;

}
// so it is as easy as
public class ReturnsListReader implements ItemReader<List<?>> {
   public List<?> read() throws Exception {
      // ... reader logic
   }
}

the processor works the same

public class FooProcessor implements ItemProcessor<List<?>, List<?>> {

    @Override
    public List<?> process(List<?> item) throws Exception {
        // ... logic
    }

}

instead of returning a list, the processor can return anything e.g. a String

public class FooProcessor implements ItemProcessor<List<?>, String> {

    @Override
    public String process(List<?> item) throws Exception {
        // ... logic
    }

}

Problem

Question is : How to make an Item reader in spring batch to deliver a list instead of a single object. I have searched across, some answers are to modify the item reader to return list of objects and changing item processor to accept a list as input. How to do/code the item reader ?

Original source