diff --git a/xstream-distribution/src/content/download.html b/xstream-distribution/src/content/download.html
index 689437e1f..d346f51d4 100644
--- a/xstream-distribution/src/content/download.html
+++ b/xstream-distribution/src/content/download.html
@@ -21,17 +21,17 @@
Stable Version: 1.4.11.1
@@ -40,8 +40,8 @@ Previous Releases
Previous releases of XStream are also available. However, use of the latest stable version is recommended.
Optional Dependencies
@@ -55,24 +55,24 @@ Optional Dependencies
- Supported XML parsers and packages:
- - XmlPull, the XML pull parser API and factory to detect available implementations.
+ - XmlPull, the XML pull parser API and factory to detect available implementations.
- Xpp3, an XML pull parser (recommended).
- kXML2 or kXML2-min, an XML pull parser.
- DOM4J, easy XML representation and manipulation framework.
- JDOM, easy XML representation and manipulation (superseded by JDOM2).
- JDOM2, easy XML representation and manipulation, successor of JDOM.
- - StaX, the reference implementation of the Streaming API for XML.
- - Woodstox, an alternate open source StaX implementation.
+ - StaX, the reference implementation of the Streaming API for XML.
+ - Woodstox, an alternate open source StaX implementation.
- XOM, another alternative XML API.
- Other optional 3rd party dependencies:
- - Java Activation module for the ActivationDataFlavorConverter. The dependency is required for the Java 11 runtime.
+ - Java Activation module for the ActivationDataFlavorConverter. The dependency is required for the Java 11 runtime.
- Joda Time for optional ISO8601 date/time converters in JDK 1.7 or below.
- CGLIB for optional support of some proxies generated with the CGLIB Enhancer.
- - Jettison for serialization and deserialization support with JSON. Note, that newer versions 1.3.x are no longer compatible with XStream.
- - Jettison 1.0.1 for serialization and deserialization support with JSON in JDK 1.4. Note, that newer version 1.1 is not compatible with XStream.
+ - Jettison for serialization and deserialization support with JSON. Note, that newer versions 1.3.x are no longer compatible with XStream.
+ - Jettison 1.0.1 for serialization and deserialization support with JSON in JDK 1.4. Note, that newer version 1.1 is not compatible with XStream.
@@ -82,15 +82,15 @@ Dependencies Hibernate Module
- Supported Hibernate versions:
- Supported Hibernate Envers versions:
@@ -100,8 +100,8 @@ Dependencies JMH Module
diff --git a/xstream/src/test/com/thoughtworks/acceptance/XStreamerTest.java b/xstream/src/test/com/thoughtworks/acceptance/XStreamerTest.java
index 06e212b9c..e68a8d512 100644
--- a/xstream/src/test/com/thoughtworks/acceptance/XStreamerTest.java
+++ b/xstream/src/test/com/thoughtworks/acceptance/XStreamerTest.java
@@ -26,6 +26,7 @@
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.XStreamer;
import com.thoughtworks.xstream.converters.ConversionException;
+import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.security.TypePermission;
@@ -88,6 +89,27 @@ public void testCanSerializeSelfContained() throws ClassNotFoundException, Objec
assertEquals(oos, new XStreamer().fromXML(xml));
}
+ public void testCanSerializeSelfContainedAndUsePermissions() throws ClassNotFoundException, ObjectStreamException {
+ final OpenSourceSoftware oos = new OpenSourceSoftware("Walnes", "XStream", "BSD");
+ xstream.alias("software", OpenSourceSoftware.class);
+ final String xml = new XStreamer().toXML(xstream, oos);
+ assertEquals(oos, new XStreamer().fromXML(xml, XStreamer.getDefaultPermissions()));
+ }
+
+ public void testCanSerializeSelfContainedAndUseNewDriver() throws ClassNotFoundException, ObjectStreamException {
+ final OpenSourceSoftware oos = new OpenSourceSoftware("Walnes", "XStream", "BSD");
+ xstream.alias("software", OpenSourceSoftware.class);
+ final String xml = new XStreamer().toXML(xstream, oos);
+ assertEquals(oos, new XStreamer().fromXML(new StaxDriver(), xml));
+ }
+
+ public void testCanSerializeSelfContainedUsePermissionAndNewDriver() throws ClassNotFoundException, ObjectStreamException {
+ final OpenSourceSoftware oos = new OpenSourceSoftware("Walnes", "XStream", "BSD");
+ xstream.alias("software", OpenSourceSoftware.class);
+ final String xml = new XStreamer().toXML(xstream, oos);
+ assertEquals(oos, new XStreamer().fromXML(new StaxDriver(), xml, XStreamer.getDefaultPermissions()));
+ }
+
private String normalizedXStreamXML(final String xml) throws TransformerException {
final StringWriter writer = new StringWriter();
transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(writer));
diff --git a/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java b/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
index 848ff150a..ae95bac95 100644
--- a/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
+++ b/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
@@ -13,6 +13,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
import java.util.ArrayList;
import com.thoughtworks.acceptance.AbstractAcceptanceTest;
@@ -22,22 +25,7 @@
import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import com.thoughtworks.xstream.io.binary.BinaryStreamDriver;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
-import com.thoughtworks.xstream.io.xml.BEAStaxDriver;
-import com.thoughtworks.xstream.io.xml.Dom4JDriver;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-import com.thoughtworks.xstream.io.xml.JDom2Driver;
-import com.thoughtworks.xstream.io.xml.JDomDriver;
-import com.thoughtworks.xstream.io.xml.KXml2DomDriver;
-import com.thoughtworks.xstream.io.xml.KXml2Driver;
-import com.thoughtworks.xstream.io.xml.SimpleStaxDriver;
-import com.thoughtworks.xstream.io.xml.StandardStaxDriver;
-import com.thoughtworks.xstream.io.xml.StaxDriver;
-import com.thoughtworks.xstream.io.xml.WstxDriver;
-import com.thoughtworks.xstream.io.xml.XomDriver;
-import com.thoughtworks.xstream.io.xml.Xpp3DomDriver;
-import com.thoughtworks.xstream.io.xml.Xpp3Driver;
-import com.thoughtworks.xstream.io.xml.XppDomDriver;
-import com.thoughtworks.xstream.io.xml.XppDriver;
+import com.thoughtworks.xstream.io.xml.*;
import junit.framework.Assert;
import junit.framework.Test;
@@ -140,6 +128,44 @@ private void testStream(final HierarchicalStreamDriver driver) {
reader.close();
}
+ static class Phone {
+ String name;
+ int number;
+ }
+
+ private void testDriverFromFile(final HierarchicalStreamDriver driver, final File file) throws Exception {
+ final XStream xStream = new XStream(driver);
+ xStream.alias("phone", Phone.class);
+ xStream.allowTypesByWildcard(this.getClass().getName() + "$*");
+
+ final Phone phone = xStream.fromXML(file);
+ Assert.assertEquals("apple", phone.name);
+ Assert.assertEquals(20200317, phone.number);
+ }
+
+ private void testDriverFromURL(final HierarchicalStreamDriver driver, final URL url, final String expect) {
+ final XStream xStream = new XStream(driver);
+ xStream.allowTypesByWildcard(this.getClass().getName() + "$*");
+ xStream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*Object.**");
+ xStream.alias("url", URL.class);
+ String result = xStream.toXML(url);
+ Assert.assertEquals(expect, result);
+
+ final URL resultURL= xStream.fromXML(result);
+ Assert.assertEquals(url, resultURL);
+ }
+
+ private void testBinaryStreamDriverFromURL(final HierarchicalStreamDriver driver, final URL url) {
+ final XStream xStream = new XStream(driver);
+ xStream.allowTypesByWildcard(this.getClass().getName() + "$*");
+ xStream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*Object.**");
+ ByteArrayOutputStream buff = new ByteArrayOutputStream();
+ xStream.toXML(url, buff);
+
+ final URL resultURL= xStream.fromXML(new ByteArrayInputStream(buff.toByteArray()));
+ Assert.assertEquals(url, resultURL);
+ }
+
private void addDriverTest(final HierarchicalStreamDriver driver) {
final String testName = getShortName(driver);
addTest(new TestCase(testName + "_Object") {
@@ -154,6 +180,47 @@ protected void runTest() throws Throwable {
testStream(driver);
}
});
+ addTest(new TestCase(testName + "_File") {
+ @Override
+ protected void runTest() throws Throwable {
+ if(driver instanceof BEAStaxDriver || driver instanceof BinaryStreamDriver) {
+ //
+ } else if(driver instanceof JettisonMappedXmlDriver) {
+ testDriverFromFile(driver, createTestJsonFile());
+ } else {
+ testDriverFromFile(driver, createTestFile());
+ }
+ }
+ });
+
+ addTest(new TestCase(testName + "_URL") {
+ @Override
+ protected void runTest() throws Throwable {
+ runDriverFromURLTest(driver, new URL("http://x-stream.github.io"), "http://x-stream.github.io");
+ runDriverFromURLTest(driver, new URL("file:/c:/winnt/blah.txt"), "file:/c:/winnt/blah.txt");
+ }
+ });
+ }
+
+ private void runDriverFromURLTest(final HierarchicalStreamDriver driver, final URL url, final String expect) {
+ if (driver instanceof BinaryStreamDriver) {
+ testBinaryStreamDriverFromURL(driver, url);
+ } else if (driver instanceof BEAStaxDriver) {
+ testDriverFromURL(driver, url, "" + expect);
+ } else if (driver instanceof StandardStaxDriver) {
+ testDriverFromURL(driver, url, "" + expect);
+ } else if (driver instanceof WstxDriver || driver instanceof StaxDriver) {
+ testDriverFromURL(driver, url, "" + expect);
+ } else if (driver instanceof Dom4JDriver) {
+ testDriverFromURL(driver, url, "\n\n" + expect);
+ } else if (driver instanceof JettisonMappedXmlDriver) {
+ final String expectJson = "http://x-stream.github.io".equals(expect)
+ ? "{\"url\":\"http:\\/\\/x-stream.github.io\"}"
+ : "{\"url\":\"file:\\/c:\\/winnt\\/blah.txt\"}";
+ testDriverFromURL(driver, url, expectJson);
+ } else {
+ testDriverFromURL(driver, url, expect);
+ }
}
private String getShortName(final HierarchicalStreamDriver driver) {
@@ -162,4 +229,32 @@ private String getShortName(final HierarchicalStreamDriver driver) {
return result;
}
+ private File createTestFile() throws Exception {
+ final String xml = "" //
+ + "\n"
+ + " apple\n"
+ + " 20200317\n"
+ + "";
+
+ final File dir = new File("target/test-data");
+ dir.mkdirs();
+ final File file = new File(dir, "test.xml");
+ final FileOutputStream fos = new FileOutputStream(file);
+ fos.write(xml.getBytes("UTF-8"));
+ fos.close();
+ return file;
+ }
+
+ private File createTestJsonFile() throws Exception {
+ final String json = "{'phone':{'name':'apple','number':20200317}}".replace('\'','"');
+
+ final File dir = new File("target/test-data");
+ dir.mkdirs();
+ final File file = new File(dir, "test.json");
+ final FileOutputStream fos = new FileOutputStream(file);
+ fos.write(json.getBytes("UTF-8"));
+ fos.close();
+ return file;
+ }
+
}