RESOLVED - issue BATCH-448: StaxEventItemWriter creates invalid xml for zero row documents
http://jira.springframework.org/browse/BATCH-448 added empty character event before writing the end tag manually
This commit is contained in:
@@ -316,7 +316,13 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements
|
||||
|
||||
// writer.writeEndDocument(); <- this doesn't work after restart
|
||||
// we need to write end tag of the root element manually
|
||||
|
||||
//harmless event to close the root tag if there were no items
|
||||
XMLEventFactory factory = XMLEventFactory.newInstance();
|
||||
writer.add(factory.createCharacters(""));
|
||||
|
||||
writer.flush();
|
||||
|
||||
ByteBuffer bbuf = ByteBuffer.wrap(("</" + getRootTagName() + ">").getBytes());
|
||||
try {
|
||||
channel.write(bbuf);
|
||||
|
||||
@@ -163,6 +163,7 @@ public class StaxEventItemWriterTests extends TestCase {
|
||||
assertTrue(outputFileContent().indexOf("<testroot attribute=\"value\"") != NOT_FOUND);
|
||||
|
||||
writer.close(null);
|
||||
assertTrue(outputFileContent().indexOf("<testroot attribute=\"value\">") != NOT_FOUND);
|
||||
assertTrue(outputFileContent().endsWith("</testroot>"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user