Creating an element reader to return a list instead of a single object - Spring package

Question: how to make an element reader in a spring folder to deliver a list instead of a single object.

I looked through several answers to change the element reader to return a list of objects and change the element processor to accept the list as input.

How to make / encode an element reader?

+3
source share
1 answer

see 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 with 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, for example. line

 public class FooProcessor implements ItemProcessor<List<?>, String> { @Override public String process(List<?> item) throws Exception { // ... logic } } 
+4
source

All Articles