diff --git a/src/main/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoder.java b/src/main/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoder.java index 929e65660..964f91145 100644 --- a/src/main/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoder.java +++ b/src/main/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoder.java @@ -176,7 +176,9 @@ public void literal(final String name, final String value) { @Override protected void onResetStream() { - writeFooter(); + if (!atStreamStart) { + writeFooter(); + } sendAndClearData(); atStreamStart = true; } diff --git a/src/test/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoderTest.java b/src/test/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoderTest.java index 6bdccb089..9aeb27a43 100644 --- a/src/test/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoderTest.java +++ b/src/test/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoderTest.java @@ -15,9 +15,6 @@ */ package org.culturegraph.mf.stream.converter.xml; - - - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -55,7 +52,7 @@ public void process(final String obj) { } }); resultCollector = new StringBuilder(); -} + } @Test public void issue249_shouldNotEmitClosingRootTagOnCloseStreamIfNoOutputWasGenerated() { @@ -64,6 +61,13 @@ public void issue249_shouldNotEmitClosingRootTagOnCloseStreamIfNoOutputWasGenera assertTrue(getResultXml().isEmpty()); } + @Test + public void shouldNotEmitClosingRootTagOnResetStreamIfNoOutputWasGenerated() { + simpleXmlEncoder.resetStream(); + + assertTrue(getResultXml().isEmpty()); + } + @Test public void shouldOnlyEscapeXmlReservedCharacters() { final StringBuilder builder = new StringBuilder();