title: Spring Batch how to process list of data before write in a Step
body: <p>I am trying to read client data from database and write processed data to a flat file.
  But I need to process whole result of the <code>ItemReader</code> before write data.</p>
  
  <p>For example, I am reading Client from database rows :</p>
  
  <pre><code>public class Client {
      private String id;
      private String subscriptionCode;
      private Boolean activated;
  }
  </code></pre>
  
  <p>But I want to count and write how many user are activated grouped by subscriptionCode :</p>
  
  <pre><code>public class Subscription {
      private String subscriptionCode;
      private Integer activatedUserCount;
  }
  </code></pre>
  
  <p>I don't know how to perform that using <code>ItemReader</code>/<code>ItemProcessor</code>/<code>ItemWriter</code>, can you help me ?</p>
  
  <p>BatchConfiguration :</p>
  
  <pre><code>@CommonsLog
  @Configuration
  @EnableBatchProcessing
  @EnableAutoConfiguration
  public class BatchConfiguration {
  
      @Autowired
      private JobBuilderFactory jobBuilderFactory;
  
      @Autowired
      private StepBuilderFactory stepBuilderFactory;
  
      @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                  .&lt;Client, Client&gt; chunk(1000)
                  .reader(new ListItemReader&lt;Client&gt;(new ArrayList&lt;Client&gt;() { // Just for test
                      {
                          add(Client.builder().id("1").subscriptionCode("AA").activated(true).build());
                          add(Client.builder().id("2").subscriptionCode("BB").activated(true).build());
                          add(Client.builder().id("3").subscriptionCode("AA").activated(false).build());
                          add(Client.builder().id("4").subscriptionCode("AA").activated(true).build());
                      }
                  }))
                  .processor(new ItemProcessor&lt;Client, Client&gt;() {
                      public Client process(Client item) throws Exception {
                          log.info(item);
                          return item;
                      }
                  })
                  .writer(new ItemWriter&lt;Client&gt;() {
                      public void write(List&lt;? extends Client&gt; items) throws Exception {
                          // Only here I can use List of Client
                          // How can I process this list before to fill Subscription objects ?
                      }
                  })
                  .build();
      }
  
      @Bean
      public Job job1(Step step1) throws Exception {
          return jobBuilderFactory.get("job1").incrementer(new RunIdIncrementer()).start(step1).build();
      }
  }
  </code></pre>
  
  <p>Main application:</p>
  
  <pre><code>public class App {
      public static void main(String[] args) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
          System.exit(SpringApplication.exit(SpringApplication.run(BatchConfiguration.class, args)));
      }
  }
  </code></pre>