diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java index 8852c7db6..2efbd6650 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java @@ -8,7 +8,6 @@ import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -111,7 +110,7 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implemen private boolean saveState = true; - private List headers = new ArrayList(); + private List headers = new ArrayList(); public StaxEventItemWriter() { setName(ClassUtils.getShortName(StaxEventItemWriter.class)); @@ -220,11 +219,13 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implemen /** * Setter for the headers. This list will be marshalled and output before - * any calls to {@link #write(List)}. + * any calls to {@link #write(List)}. Header item type is not restricted, + * but note the {@link #setMarshaller(Marshaller)} needs to support + * the type. * @param headers */ - public void setHeaderItems(T[] headers) { - this.headers = Arrays.asList(headers); + public void setHeaderItems(List headers) { + this.headers = headers; } public void setSaveState(boolean saveState) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java index 172d8e025..b7b6832be 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java @@ -10,6 +10,7 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -103,9 +104,9 @@ public class StaxEventItemWriterTests { */ @Test public void testWriteWithHeader() throws Exception { - Object header1 = new Object(); - Object header2 = new Object(); - writer.setHeaderItems(new Object[] { header1, header2 }); + final Object header1 = new Object(); + final Object header2 = new Object(); + writer.setHeaderItems(new ArrayList() {{add(header1); add(header2); }}); writer.open(executionContext); writer.write(items); String content = outputFileContent(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java index 5e5daa47e..272e94ed5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java @@ -93,7 +93,7 @@ public class TransactionalStaxEventItemWriterTests { @Test public void testWriteWithHeaderAfterRollback() throws Exception { Object header = new Object(); - writer.setHeaderItems(new Object[] { header }); + writer.setHeaderItems(Collections.singletonList(header)); writer.open(executionContext); try { new TransactionTemplate(transactionManager).execute(new TransactionCallback() { @@ -137,7 +137,7 @@ public class TransactionalStaxEventItemWriterTests { @Test public void testWriteWithHeaderAfterFlushAndRollback() throws Exception { Object header = new Object(); - writer.setHeaderItems(new Object[] { header }); + writer.setHeaderItems(Collections.singletonList(header)); writer.open(executionContext); new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) {