RESOLVED - BATCH-776: StaxEventItemWriter headers should not have to be the same type as the T that the writer is parameterised with
This commit is contained in:
@@ -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<T> extends ExecutionContextUserSupport implemen
|
||||
|
||||
private boolean saveState = true;
|
||||
|
||||
private List<? extends T> headers = new ArrayList<T>();
|
||||
private List<?> headers = new ArrayList<Object>();
|
||||
|
||||
public StaxEventItemWriter() {
|
||||
setName(ClassUtils.getShortName(StaxEventItemWriter.class));
|
||||
@@ -220,11 +219,13 @@ public class StaxEventItemWriter<T> 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) {
|
||||
|
||||
@@ -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<Object>() {{add(header1); add(header2); }});
|
||||
writer.open(executionContext);
|
||||
writer.write(items);
|
||||
String content = outputFileContent();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user