title: Return multiple items from spring batch ItemProcessor
body: <p>I'm writing a spring batch job and in one of my step I have the following code for the processor:</p>
  
  <pre><code>@Component
  public class SubscriberProcessor implements ItemProcessor&lt;NewsletterSubscriber, Account&gt;, InitializingBean {
  
      @Autowired
      private AccountService service;
  
      @Override public Account process(NewsletterSubscriber item) throws Exception {
          if (!Strings.isNullOrEmpty(item.getId())) {
              return service.getAccount(item.getId());
          }
          // search with email address
          List&lt;Account&gt; accounts = service.findByEmail(item.getEmail());
          checkState(accounts.size() &lt;= 1, "Found more than one account with email %s", item.getEmail());
          return accounts.isEmpty() ? null : accounts.get(0);
      }
  
      @Override public void afterPropertiesSet() throws Exception {
          Assert.notNull(service, "account service must be set");
      }
  }
  </code></pre>
  
  <p>The above code works but I've found out that there are some edge cases where having more than one <code>Account</code> per <code>NewsletterSubscriber</code> is allowed. So I need to remove the state check and to pass more than one <code>Account</code> to the item writer.</p>
  
  <p>One solution I found is to change both <code>ItemProcessor</code> and <code>ItemWriter</code> to deal with <code>List&lt;Account&gt;</code> type instead of <code>Account</code> but this have two drawbacks:</p>
  
  <ul>
  <li>Code and tests are uglier and harder to write and maintain because of nested lists in writer</li>
  <li>Most important more than one <code>Account</code> object may be written in the same transaction because a list given to writer may contain multiple accounts and I'd like to avoid this.</li>
  </ul>
  
  <p>Is there any way, maybe using a listener, or replacing some internal component used by spring batch to avoid lists in processor?</p>
  
  <h2>Update</h2>
  
  <p>I've opened <a href="https://jira.spring.io/browse/BATCH-2252" rel="noreferrer">an issue on spring Jira</a> for this problem.</p>
  
  <p>I'm looking into <a href="https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java#L160" rel="noreferrer">isComplete</a> and <a href="https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java#L180" rel="noreferrer">getAdjustedOutputs</a> methods in <code>FaultTolerantChunkProcessor</code> which are marked as extension points in <a href="https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java#L233" rel="noreferrer"><code>SimpleChunkProcessor</code></a> to see if I can use them in some way to achieve my goal. </p>
  
  <p>Any hint is welcome.</p>