Skip to content

Commit 30efa4d

Browse files
committed
Change default driver in XStreamMarshaller from XppDriver to DomDriver
As explained in commit a247b83, the XppDriver from XStream relies on the XPP3 library which publishes javax.xml.namespace.QName as part of its JAR. The QName type is also published by the java.xml system module in modular JREs (i.e., Java 9 or higher). This results in a split package between the unnamed module and the java.xml system module, which the Java Language Specification defines as illegal (see §6.5.5.2 and §7.4.3). Most Java compilers do not currently enforce this rule; however, the Eclipse compiler does. This makes it impossible to use spring-oxm out of the box in the Eclipse IDE. In addition, if bug JDK-8215739 is fixed in future versions of other JDK implementations, this rule will affect any users using spring-oxm with those JDKs. This commit therefore switches the default driver in XStreamMarshaller from XppDriver to DomDriver. Users can naturally switch back to the XppDriver if they wish, since the driver is configurable. Closes gh-27464
1 parent 50f2016 commit 30efa4d

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
import com.thoughtworks.xstream.io.StreamException;
5353
import com.thoughtworks.xstream.io.naming.NameCoder;
5454
import com.thoughtworks.xstream.io.xml.CompactWriter;
55+
import com.thoughtworks.xstream.io.xml.DomDriver;
5556
import com.thoughtworks.xstream.io.xml.DomReader;
5657
import com.thoughtworks.xstream.io.xml.DomWriter;
5758
import com.thoughtworks.xstream.io.xml.QNameMap;
5859
import com.thoughtworks.xstream.io.xml.SaxWriter;
5960
import com.thoughtworks.xstream.io.xml.StaxReader;
6061
import com.thoughtworks.xstream.io.xml.StaxWriter;
6162
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
62-
import com.thoughtworks.xstream.io.xml.XppDriver;
6363
import com.thoughtworks.xstream.mapper.CannotResolveClassException;
6464
import com.thoughtworks.xstream.mapper.Mapper;
6565
import com.thoughtworks.xstream.mapper.MapperWrapper;
@@ -112,6 +112,11 @@
112112
* Note that {@link XStream} construction has been reworked in 4.0, with the
113113
* stream driver and the class loader getting passed into XStream itself now.
114114
*
115+
* <p>As of Spring Framework 6.0, the default {@link HierarchicalStreamDriver} is
116+
* a {@link DomDriver} that uses the configured {@linkplain #setEncoding(String)
117+
* encoding} and {@link #setNameCoder(NameCoder) NameCoder}. The driver can be
118+
* changed via {@link #setStreamDriver(HierarchicalStreamDriver)}.
119+
*
115120
* @author Peter Meijer
116121
* @author Arjen Poutsma
117122
* @author Juergen Hoeller
@@ -205,7 +210,7 @@ public void setReflectionProvider(ReflectionProvider reflectionProvider) {
205210
}
206211

207212
/**
208-
* Set a XStream {@link HierarchicalStreamDriver} to be used for readers and writers.
213+
* Set an XStream {@link HierarchicalStreamDriver} to be used for readers and writers.
209214
* <p>As of Spring 4.0, this stream driver will also be passed to the {@link XStream}
210215
* constructor and therefore used by streaming-related native API methods themselves.
211216
*/
@@ -216,7 +221,7 @@ public void setStreamDriver(HierarchicalStreamDriver streamDriver) {
216221

217222
private HierarchicalStreamDriver getDefaultDriver() {
218223
if (this.defaultDriver == null) {
219-
this.defaultDriver = new XppDriver();
224+
this.defaultDriver = new DomDriver(this.encoding, this.nameCoder);
220225
}
221226
return this.defaultDriver;
222227
}

spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
4444
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
4545
import com.thoughtworks.xstream.io.json.JsonWriter;
46-
import com.thoughtworks.xstream.io.xml.DomDriver;
47-
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
4846
import com.thoughtworks.xstream.security.AnyTypePermission;
4947
import org.junit.jupiter.api.BeforeEach;
5048
import org.junit.jupiter.api.Test;
@@ -86,7 +84,6 @@ void createMarshaller() {
8684
marshaller = new XStreamMarshaller();
8785
marshaller.setTypePermissions(AnyTypePermission.ANY);
8886
marshaller.setAliases(Collections.singletonMap("flight", Flight.class.getName()));
89-
marshaller.setStreamDriver(new DomDriver("UTF-8", new XmlFriendlyNameCoder()));
9087
flight.setFlightNumber(42L);
9188
}
9289

spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamUnmarshallerTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import javax.xml.transform.dom.DOMSource;
3131
import javax.xml.transform.stream.StreamSource;
3232

33-
import com.thoughtworks.xstream.io.xml.DomDriver;
34-
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
3533
import com.thoughtworks.xstream.security.AnyTypePermission;
3634
import org.junit.jupiter.api.BeforeEach;
3735
import org.junit.jupiter.api.Test;
@@ -57,7 +55,6 @@ public class XStreamUnmarshallerTests {
5755
public void createUnmarshaller() {
5856
unmarshaller = new XStreamMarshaller();
5957
unmarshaller.setTypePermissions(AnyTypePermission.ANY);
60-
unmarshaller.setStreamDriver(new DomDriver("UTF-8", new XmlFriendlyNameCoder()));
6158
Map<String, Class<?>> aliases = new HashMap<>();
6259
aliases.put("flight", Flight.class);
6360
unmarshaller.setAliases(aliases);

0 commit comments

Comments
 (0)