diff --git a/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java index ccb10d27c172..342f9a41edac 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java @@ -52,6 +52,7 @@ import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; import com.thoughtworks.xstream.io.xml.CompactWriter; +import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomReader; import com.thoughtworks.xstream.io.xml.DomWriter; import com.thoughtworks.xstream.io.xml.QNameMap; @@ -59,7 +60,6 @@ import com.thoughtworks.xstream.io.xml.StaxReader; import com.thoughtworks.xstream.io.xml.StaxWriter; import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder; -import com.thoughtworks.xstream.io.xml.XppDriver; import com.thoughtworks.xstream.mapper.CannotResolveClassException; import com.thoughtworks.xstream.mapper.Mapper; import com.thoughtworks.xstream.mapper.MapperWrapper; @@ -112,6 +112,11 @@ * Note that {@link XStream} construction has been reworked in 4.0, with the * stream driver and the class loader getting passed into XStream itself now. * + *

As of Spring Framework 6.0, the default {@link HierarchicalStreamDriver} is + * a {@link DomDriver} that uses the configured {@linkplain #setEncoding(String) + * encoding} and {@link #setNameCoder(NameCoder) NameCoder}. The driver can be + * changed via {@link #setStreamDriver(HierarchicalStreamDriver)}. + * * @author Peter Meijer * @author Arjen Poutsma * @author Juergen Hoeller @@ -205,7 +210,7 @@ public void setReflectionProvider(ReflectionProvider reflectionProvider) { } /** - * Set a XStream {@link HierarchicalStreamDriver} to be used for readers and writers. + * Set an XStream {@link HierarchicalStreamDriver} to be used for readers and writers. *

As of Spring 4.0, this stream driver will also be passed to the {@link XStream} * constructor and therefore used by streaming-related native API methods themselves. */ @@ -216,7 +221,7 @@ public void setStreamDriver(HierarchicalStreamDriver streamDriver) { private HierarchicalStreamDriver getDefaultDriver() { if (this.defaultDriver == null) { - this.defaultDriver = new XppDriver(); + this.defaultDriver = new DomDriver(this.encoding, this.nameCoder); } return this.defaultDriver; } diff --git a/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java index ece6236ecd75..b408c6611be3 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java @@ -43,8 +43,6 @@ import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; import com.thoughtworks.xstream.io.json.JsonWriter; -import com.thoughtworks.xstream.io.xml.DomDriver; -import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder; import com.thoughtworks.xstream.security.AnyTypePermission; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -86,7 +84,6 @@ void createMarshaller() { marshaller = new XStreamMarshaller(); marshaller.setTypePermissions(AnyTypePermission.ANY); marshaller.setAliases(Collections.singletonMap("flight", Flight.class.getName())); - marshaller.setStreamDriver(new DomDriver("UTF-8", new XmlFriendlyNameCoder())); flight.setFlightNumber(42L); } diff --git a/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamUnmarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamUnmarshallerTests.java index 9d8d61b7bea6..7c87eda2253b 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamUnmarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/xstream/XStreamUnmarshallerTests.java @@ -30,8 +30,6 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; -import com.thoughtworks.xstream.io.xml.DomDriver; -import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder; import com.thoughtworks.xstream.security.AnyTypePermission; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -57,7 +55,6 @@ public class XStreamUnmarshallerTests { public void createUnmarshaller() { unmarshaller = new XStreamMarshaller(); unmarshaller.setTypePermissions(AnyTypePermission.ANY); - unmarshaller.setStreamDriver(new DomDriver("UTF-8", new XmlFriendlyNameCoder())); Map> aliases = new HashMap<>(); aliases.put("flight", Flight.class); unmarshaller.setAliases(aliases);