提交 37861c3f 编写于 作者: A Arjen Poutsma 提交者: Rossen Stoyanchev

Support 'empty' StreamSource in Jaxb2Marshaller

Added support for StreamSources that do not have a InputStream or
Reader, but do have a System ID.

Issue: 10828
上级 319f18dd
......@@ -791,6 +791,9 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
else if (streamSource.getReader() != null) {
inputSource = new InputSource(streamSource.getReader());
}
else {
inputSource = new InputSource(streamSource.getSystemId());
}
}
try {
......
......@@ -16,8 +16,9 @@
package org.springframework.oxm.jaxb;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.bind.JAXBElement;
......@@ -26,7 +27,11 @@ import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import static org.junit.Assert.*;
import org.junit.Test;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.oxm.AbstractUnmarshallerTests;
......@@ -36,9 +41,6 @@ import org.springframework.oxm.jaxb.test.Flights;
import org.springframework.oxm.mime.MimeContainer;
import org.springframework.util.xml.StaxUtils;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* @author Arjen Poutsma
* @author Biju Kunjummen
......@@ -134,4 +136,13 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests {
"test", airplane.getValue().getName());
}
@Test
public void unmarshalFile() throws IOException {
Resource resource = new ClassPathResource("jaxb2.xml", getClass());
File file = resource.getFile();
Flights f = (Flights) unmarshaller.unmarshal(new StreamSource(file));
testFlights(f);
}
}
<tns:flights xmlns:tns="http://samples.springframework.org/flight">
<tns:flight>
<tns:number>42</tns:number>
</tns:flight>
</tns:flights>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册