Browse Source

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
pull/333/merge
Arjen Poutsma 12 years ago committed by Rossen Stoyanchev
parent
commit
37861c3f90
  1. 3
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java
  2. 19
      spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java
  3. 5
      spring-oxm/src/test/resources/org/springframework/oxm/jaxb/jaxb2.xml

3
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

@ -791,6 +791,9 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi @@ -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 {

19
spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java

@ -16,8 +16,9 @@ @@ -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; @@ -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; @@ -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 { @@ -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);
}
}

5
spring-oxm/src/test/resources/org/springframework/oxm/jaxb/jaxb2.xml

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<tns:flights xmlns:tns="http://samples.springframework.org/flight">
<tns:flight>
<tns:number>42</tns:number>
</tns:flight>
</tns:flights>
Loading…
Cancel
Save