Index: 3rdParty_sources/versions.txt
===================================================================
diff -u -rb69db8c0c19115290e73865c3c51b408b78f41c9 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/versions.txt (.../versions.txt) (revision b69db8c0c19115290e73865c3c51b408b78f41c9)
+++ 3rdParty_sources/versions.txt (.../versions.txt) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -59,6 +59,6 @@
xmltooling 1.4.0
-XStream 1.5.0
+XStream 1.4.10
websocket api_1.1_spec-1.1.1.Final
\ No newline at end of file
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/InitializationException.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/InitializationException.java (.../InitializationException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/InitializationException.java (.../InitializationException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2013 XStream Committers.
+ * Copyright (C) 2007, 2008 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -17,7 +17,7 @@
* @author Jörg Schaible
* @since 1.3
*/
-public class InitializationException extends XStreamException {
+public class InitializationException extends XStream.InitializationException {
public InitializationException(String message, Throwable cause) {
super(message, cause);
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/MarshallingStrategy.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/MarshallingStrategy.java (.../MarshallingStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/MarshallingStrategy.java (.../MarshallingStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2006 Joe Walnes.
- * Copyright (C) 2007, 2009, 2014 XStream Committers.
+ * Copyright (C) 2007, 2009 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -17,38 +17,8 @@
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.mapper.Mapper;
-
-/**
- * Core interface for a marshalling strategy.
- *
- * An implementation dictates how an object graph is marshalled and unmarshalled. It is the implementation's
- * responsibility to deal with references between the objects.
- *
- */
public interface MarshallingStrategy {
- /**
- * Marshal an object graph.
- *
- * @param writer the target for the marshalled data
- * @param obj the object to marshal
- * @param converterLookup the converter store
- * @param mapper the mapper chain
- * @param dataHolder the holder for additional data and state while marshalling
- */
- void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper,
- DataHolder dataHolder);
-
- /**
- * Unmarshal an object graph.
- *
- * @param root a possible root object (should be {@code null} in normal cases)
- * @param reader the source for the unmarshalled object data
- * @param dataHolder the holder for additional data and state while marshalling
- * @param converterLookup the converter store
- * @param mapper the mapper chain
- * @return the unmarshalled object
- */
- Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup,
- Mapper mapper);
+ Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper);
+ void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder);
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/XStream.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/XStream.java (.../XStream.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/XStream.java (.../XStream.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,12 +1,12 @@
/*
* Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
- * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
- *
+ *
* Created on 26. September 2003 by Joe Walnes
*/
package com.thoughtworks.xstream;
@@ -26,6 +26,7 @@
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.math.BigDecimal;
@@ -35,21 +36,17 @@
import java.nio.charset.Charset;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Currency;
import java.util.Date;
-import java.util.EnumMap;
-import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -60,18 +57,18 @@
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.TreeSet;
-import java.util.UUID;
import java.util.Vector;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.ConverterLookup;
import com.thoughtworks.xstream.converters.ConverterRegistry;
import com.thoughtworks.xstream.converters.DataHolder;
+import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.basic.BigDecimalConverter;
import com.thoughtworks.xstream.converters.basic.BigIntegerConverter;
import com.thoughtworks.xstream.converters.basic.BooleanConverter;
@@ -85,11 +82,9 @@
import com.thoughtworks.xstream.converters.basic.NullConverter;
import com.thoughtworks.xstream.converters.basic.ShortConverter;
import com.thoughtworks.xstream.converters.basic.StringBufferConverter;
-import com.thoughtworks.xstream.converters.basic.StringBuilderConverter;
import com.thoughtworks.xstream.converters.basic.StringConverter;
import com.thoughtworks.xstream.converters.basic.URIConverter;
import com.thoughtworks.xstream.converters.basic.URLConverter;
-import com.thoughtworks.xstream.converters.basic.UUIDConverter;
import com.thoughtworks.xstream.converters.collections.ArrayConverter;
import com.thoughtworks.xstream.converters.collections.BitSetConverter;
import com.thoughtworks.xstream.converters.collections.CharArrayConverter;
@@ -100,12 +95,7 @@
import com.thoughtworks.xstream.converters.collections.SingletonMapConverter;
import com.thoughtworks.xstream.converters.collections.TreeMapConverter;
import com.thoughtworks.xstream.converters.collections.TreeSetConverter;
-import com.thoughtworks.xstream.converters.enums.EnumConverter;
-import com.thoughtworks.xstream.converters.enums.EnumMapConverter;
-import com.thoughtworks.xstream.converters.enums.EnumSetConverter;
-import com.thoughtworks.xstream.converters.extended.CharsetConverter;
import com.thoughtworks.xstream.converters.extended.ColorConverter;
-import com.thoughtworks.xstream.converters.extended.CurrencyConverter;
import com.thoughtworks.xstream.converters.extended.DynamicProxyConverter;
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
import com.thoughtworks.xstream.converters.extended.FileConverter;
@@ -116,13 +106,10 @@
import com.thoughtworks.xstream.converters.extended.JavaMethodConverter;
import com.thoughtworks.xstream.converters.extended.LocaleConverter;
import com.thoughtworks.xstream.converters.extended.LookAndFeelConverter;
-import com.thoughtworks.xstream.converters.extended.RegexPatternConverter;
import com.thoughtworks.xstream.converters.extended.SqlDateConverter;
import com.thoughtworks.xstream.converters.extended.SqlTimeConverter;
import com.thoughtworks.xstream.converters.extended.SqlTimestampConverter;
-import com.thoughtworks.xstream.converters.extended.StackTraceElementConverter;
import com.thoughtworks.xstream.converters.extended.TextAttributeConverter;
-import com.thoughtworks.xstream.converters.extended.ThrowableConverter;
import com.thoughtworks.xstream.converters.reflection.ExternalizableConverter;
import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
@@ -143,7 +130,7 @@
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.StatefulWriter;
import com.thoughtworks.xstream.io.xml.XppDriver;
-import com.thoughtworks.xstream.mapper.AnnotationMapper;
+import com.thoughtworks.xstream.mapper.AnnotationConfiguration;
import com.thoughtworks.xstream.mapper.ArrayMapper;
import com.thoughtworks.xstream.mapper.AttributeAliasingMapper;
import com.thoughtworks.xstream.mapper.AttributeMapper;
@@ -152,7 +139,7 @@
import com.thoughtworks.xstream.mapper.DefaultImplementationsMapper;
import com.thoughtworks.xstream.mapper.DefaultMapper;
import com.thoughtworks.xstream.mapper.DynamicProxyMapper;
-import com.thoughtworks.xstream.mapper.EnumMapper;
+import com.thoughtworks.xstream.mapper.ElementIgnoringMapper;
import com.thoughtworks.xstream.mapper.FieldAliasingMapper;
import com.thoughtworks.xstream.mapper.ImmutableTypesMapper;
import com.thoughtworks.xstream.mapper.ImplicitCollectionMapper;
@@ -183,125 +170,143 @@
*
*
* Example
- *
+ *
*
* XStream xstream = new XStream();
* String xml = xstream.toXML(myObject); // serialize to XML
* Object myObject2 = xstream.fromXML(xml); // deserialize from XML
*
- *
+ *
*
*
+ *
*
Aliasing classes
+ *
*
- * To create shorter XML, you can specify aliases for classes using the alias() method. For example, you
- * can shorten all occurrences of element <com.blah.MyThing> to <my-thing> by
- * registering an alias for the class.
+ * To create shorter XML, you can specify aliases for classes using the alias()
+ * method. For example, you can shorten all occurrences of element
+ * <com.blah.MyThing> to <my-thing> by registering an
+ * alias for the class.
*
*
*
- *
+ *
*
* xstream.alias("my-thing", MyThing.class);
*
- *
+ *
*
*
+ *
*
Converters
+ *
*
- * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each of which acts as a
- * strategy for converting a particular type of class to XML and back again. Out of the box, XStream contains converters
- * for most basic types (String, Date, int, boolean, etc) and collections (Map, List, Set, Properties, etc). For other
- * objects reflection is used to serialize each field recursively.
+ * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each
+ * of which acts as a strategy for converting a particular type of class to XML and back again. Out
+ * of the box, XStream contains converters for most basic types (String, Date, int, boolean, etc)
+ * and collections (Map, List, Set, Properties, etc). For other objects reflection is used to
+ * serialize each field recursively.
*
+ *
*
- * Extra converters can be registered using the registerConverter() method. Some non-standard converters
- * are supplied in the {@link com.thoughtworks.xstream.converters.extended} package and you can create your own by
- * implementing the {@link com.thoughtworks.xstream.converters.Converter} interface.
+ * Extra converters can be registered using the registerConverter() method. Some
+ * non-standard converters are supplied in the {@link com.thoughtworks.xstream.converters.extended}
+ * package and you can create your own by implementing the
+ * {@link com.thoughtworks.xstream.converters.Converter} interface.
*
- * The converters can be registered with an explicit priority. By default they are registered with
- * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence they have been registered.
- * The default converter, i.e. the converter which will be used if no other registered converter is suitable, can be
- * registered with priority XStream.PRIORITY_VERY_LOW. XStream uses by default the
- * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback converter.
+ * The converters can be registered with an explicit priority. By default they are registered with
+ * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence
+ * they have been registered. The default converter, i.e. the converter which will be used if
+ * no other registered converter is suitable, can be registered with priority
+ * XStream.PRIORITY_VERY_LOW. XStream uses by default the
+ * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback
+ * converter.
*
- * XStream has support for object graphs; a deserialized object graph will keep references intact, including circular
- * references.
+ * XStream has support for object graphs; a deserialized object graph will keep references intact,
+ * including circular references.
*
+ *
*
* XStream can signify references in XML using either relative/absolute XPath or IDs. The mode can be changed using
* setMode():
*
Uses XPath absolute references to signify duplicate references. The XPath expression ensures that a single node
- * only is selected always.
+ *
Uses XPath absolute references to signify duplicate references. The XPath expression ensures that
+ * a single node only is selected always.
*
*
*
xstream.setMode(XStream.ID_REFERENCES);
- *
Uses ID references to signify duplicate references. In some scenarios, such as when using hand-written XML, this
- * is easier to work with.
+ *
Uses ID references to signify duplicate references. In some scenarios, such as when using
+ * hand-written XML, this is easier to work with.
*
*
*
xstream.setMode(XStream.NO_REFERENCES);
- *
This disables object graph support and treats the object structure like a tree. Duplicate references are treated
- * as two separate objects and circular references cause an exception. This is slightly faster and uses less memory than
- * the other two modes.
+ *
This disables object graph support and treats the object structure like a tree. Duplicate
+ * references are treated as two separate objects and circular references cause an exception. This
+ * is slightly faster and uses less memory than the other two modes.
*
*
*
Thread safety
*
- * The XStream instance is thread-safe. That is, once the XStream instance has been created and configured, it may be
- * shared across multiple threads allowing objects to be serialized/deserialized concurrently.
- * Note, that this only applies if annotations are not
+ * The XStream instance is thread-safe. That is, once the XStream instance has been created and
+ * configured, it may be shared across multiple threads allowing objects to be
+ * serialized/deserialized concurrently. Note, that this only applies if annotations are not
* auto-detected on-the-fly.
*
*
Implicit collections
+ *
*
- * To avoid the need for special tags for collections, you can define implicit collections using one of the
- * addImplicitCollection methods.
+ * To avoid the need for special tags for collections, you can define implicit collections using one
+ * of the addImplicitCollection methods.
*
- *
+ *
* @author Joe Walnes
* @author Jörg Schaible
* @author Mauro Talevi
@@ -311,17 +316,18 @@
// CAUTION: The sequence of the fields is intentional for an optimal XML output of a
// self-serialization!
- private final ReflectionProvider reflectionProvider;
- private final HierarchicalStreamDriver hierarchicalStreamDriver;
- private final ClassLoaderReference classLoaderReference;
+ private ReflectionProvider reflectionProvider;
+ private HierarchicalStreamDriver hierarchicalStreamDriver;
+ private ClassLoaderReference classLoaderReference;
private MarshallingStrategy marshallingStrategy;
- private final ConverterLookup converterLookup;
- private final ConverterRegistry converterRegistry;
- private final Mapper mapper;
+ private ConverterLookup converterLookup;
+ private ConverterRegistry converterRegistry;
+ private Mapper mapper;
private PackageAliasingMapper packageAliasingMapper;
private ClassAliasingMapper classAliasingMapper;
private FieldAliasingMapper fieldAliasingMapper;
+ private ElementIgnoringMapper elementIgnoringMapper;
private AttributeAliasingMapper attributeAliasingMapper;
private SystemAttributeAliasingMapper systemAttributeAliasingMapper;
private AttributeMapper attributeMapper;
@@ -330,8 +336,10 @@
private ImplicitCollectionMapper implicitCollectionMapper;
private LocalConversionMapper localConversionMapper;
private SecurityMapper securityMapper;
- private AnnotationMapper annotationMapper;
+ private AnnotationConfiguration annotationConfiguration;
+ private transient boolean insecureWarning;
+
public static final int NO_REFERENCES = 1001;
public static final int ID_REFERENCES = 1002;
public static final int XPATH_RELATIVE_REFERENCES = 1003;
@@ -344,19 +352,20 @@
public static final int PRIORITY_LOW = -10;
public static final int PRIORITY_VERY_LOW = -20;
+ private static final String ANNOTATION_MAPPER_TYPE = "com.thoughtworks.xstream.mapper.AnnotationMapper";
private static final Pattern IGNORE_ALL = Pattern.compile(".*");
/**
* Constructs a default XStream.
*
- * The instance will use the {@link XppDriver} as default and tries to determine the best match for the
- * {@link ReflectionProvider} on its own.
+ * The instance will use the {@link XppDriver} as default and tries to determine the best
+ * match for the {@link ReflectionProvider} on its own.
*
- *
+ *
* @throws InitializationException in case of an initialization problem
*/
public XStream() {
- this(new XppDriver());
+ this(null, (Mapper)null, new XppDriver());
}
/**
@@ -365,179 +374,212 @@
* The instance will use the {@link XppDriver} as default.
*
*
- * @param reflectionProvider the reflection provider to use or null for best matching reflection provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching reflection provider
* @throws InitializationException in case of an initialization problem
*/
- public XStream(final ReflectionProvider reflectionProvider) {
- this(reflectionProvider, new XppDriver());
+ public XStream(ReflectionProvider reflectionProvider) {
+ this(reflectionProvider, (Mapper)null, new XppDriver());
}
/**
* Constructs an XStream with a special {@link HierarchicalStreamDriver}.
*
- * The instance will tries to determine the best match for the {@link ReflectionProvider} on its own.
+ * The instance will tries to determine the best match for the {@link ReflectionProvider} on
+ * its own.
*
- *
+ *
* @param hierarchicalStreamDriver the driver instance
* @throws InitializationException in case of an initialization problem
*/
- public XStream(final HierarchicalStreamDriver hierarchicalStreamDriver) {
- this(null, hierarchicalStreamDriver);
+ public XStream(HierarchicalStreamDriver hierarchicalStreamDriver) {
+ this(null, (Mapper)null, hierarchicalStreamDriver);
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver} and {@link ReflectionProvider}.
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver} and
+ * {@link ReflectionProvider}.
*
- * @param reflectionProvider the reflection provider to use or null for best matching Provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
* @param hierarchicalStreamDriver the driver instance
* @throws InitializationException in case of an initialization problem
*/
- public XStream(final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver hierarchicalStreamDriver) {
- this(reflectionProvider, hierarchicalStreamDriver, new ClassLoaderReference(new CompositeClassLoader()));
+ public XStream(
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
+ this(reflectionProvider, (Mapper)null, hierarchicalStreamDriver);
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and a
- * {@link ClassLoaderReference}.
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider} and a prepared {@link Mapper} chain.
*
- * @param reflectionProvider the reflection provider to use or null for best matching Provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
+ * @param mapper the instance with the {@link Mapper} chain or null for the default
+ * chain
* @param driver the driver instance
+ * @throws InitializationException in case of an initialization problem
+ * @deprecated As of 1.3, use
+ * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
+ * instead
+ */
+ public XStream(
+ ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
+ this(reflectionProvider, driver, new CompositeClassLoader(), mapper);
+ }
+
+ /**
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider} and a {@link ClassLoaderReference}.
+ *
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
+ * @param driver the driver instance
* @param classLoaderReference the reference to the {@link ClassLoader} to use
* @throws InitializationException in case of an initialization problem
* @since 1.4.5
*/
public XStream(
- final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoaderReference classLoaderReference) {
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
+ ClassLoaderReference classLoaderReference) {
this(reflectionProvider, driver, classLoaderReference, null);
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and the
- * {@link ClassLoader} to use.
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider} and the {@link ClassLoader} to use.
*
* @throws InitializationException in case of an initialization problem
* @since 1.3
- * @deprecated As of 1.4.5 use {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
+ * @deprecated As of 1.4.5 use
+ * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
*/
- @Deprecated
public XStream(
- final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoader classLoader) {
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
+ ClassLoader classLoader) {
this(reflectionProvider, driver, classLoader, null);
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
- * {@link Mapper} chain and the {@link ClassLoader} to use.
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the {@link ClassLoader}
+ * to use.
*
- * @param reflectionProvider the reflection provider to use or null for best matching Provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
* @param driver the driver instance
* @param classLoader the {@link ClassLoader} to use
- * @param mapper the instance with the {@link Mapper} chain or null for the default chain
+ * @param mapper the instance with the {@link Mapper} chain or null for the default
+ * chain
* @throws InitializationException in case of an initialization problem
* @since 1.3
* @deprecated As of 1.4.5 use
* {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper)}
*/
- @Deprecated
public XStream(
- final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoader classLoader, final Mapper mapper) {
- this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
+ ClassLoader classLoader, Mapper mapper) {
+ this(
+ reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
- * {@link Mapper} chain and the {@link ClassLoaderReference}.
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the
+ * {@link ClassLoaderReference}.
*
* The {@link ClassLoaderReference} should also be used for the {@link Mapper} chain.
*
*
- * @param reflectionProvider the reflection provider to use or null for best matching Provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
* @param driver the driver instance
* @param classLoaderReference the reference to the {@link ClassLoader} to use
- * @param mapper the instance with the {@link Mapper} chain or null for the default chain
+ * @param mapper the instance with the {@link Mapper} chain or null for the default
+ * chain
* @throws InitializationException in case of an initialization problem
* @since 1.4.5
*/
public XStream(
- final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoaderReference classLoaderReference, final Mapper mapper) {
- this(reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
+ ClassLoaderReference classLoaderReference, Mapper mapper) {
+ this(
+ reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
}
-
+
private XStream(
- final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoaderReference classLoader, final Mapper mapper,
- final DefaultConverterLookup defaultConverterLookup) {
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
+ Mapper mapper, final DefaultConverterLookup defaultConverterLookup) {
this(reflectionProvider, driver, classLoader, mapper, new ConverterLookup() {
- @Override
- public Converter lookupConverterForType(final Class> type) {
+ public Converter lookupConverterForType(Class type) {
return defaultConverterLookup.lookupConverterForType(type);
}
}, new ConverterRegistry() {
- @Override
- public void registerConverter(final Converter converter, final int priority) {
+ public void registerConverter(Converter converter, int priority) {
defaultConverterLookup.registerConverter(converter, priority);
}
});
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
- * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
+ * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
* {@link ConverterRegistry}.
*
- * @param reflectionProvider the reflection provider to use or null for best matching Provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
* @param driver the driver instance
* @param classLoader the {@link ClassLoader} to use
- * @param mapper the instance with the {@link Mapper} chain or null for the default chain
+ * @param mapper the instance with the {@link Mapper} chain or null for the default
+ * chain
* @param converterLookup the instance that is used to lookup the converters
* @param converterRegistry an instance to manage the converter instances
* @throws InitializationException in case of an initialization problem
* @since 1.3
* @deprecated As of 1.4.5 use
* {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper, ConverterLookup, ConverterRegistry)}
*/
- @Deprecated
public XStream(
- final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoader classLoader, final Mapper mapper, final ConverterLookup converterLookup,
- final ConverterRegistry converterRegistry) {
- this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup,
- converterRegistry);
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
+ ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup,
+ ConverterRegistry converterRegistry) {
+ this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup, converterRegistry);
}
/**
- * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared
- * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and
+ * Constructs an XStream with a special {@link HierarchicalStreamDriver},
+ * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
+ * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
* {@link ConverterRegistry}.
*
- * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup should access the
- * ConverterRegistry if you intent to register {@link Converter} instances with XStream facade or you are using
- * annotations.
+ * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup
+ * should access the ConverterRegistry if you intent to register {@link Converter} instances
+ * with XStream facade or you are using annotations.
*
*
- * @param reflectionProvider the reflection provider to use or null for best matching Provider
+ * @param reflectionProvider the reflection provider to use or null for best
+ * matching Provider
* @param driver the driver instance
* @param classLoaderReference the reference to the {@link ClassLoader} to use
- * @param mapper the instance with the {@link Mapper} chain or null for the default chain
+ * @param mapper the instance with the {@link Mapper} chain or null for the default
+ * chain
* @param converterLookup the instance that is used to lookup the converters
- * @param converterRegistry an instance to manage the converter instances or null to prevent any further
- * registry (including annotations)
+ * @param converterRegistry an instance to manage the converter instances or null
+ * to prevent any further registry (including annotations)
* @throws InitializationException in case of an initialization problem
* @since 1.4.5
*/
public XStream(
- ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver,
- final ClassLoaderReference classLoaderReference, final Mapper mapper,
- final ConverterLookup converterLookup, final ConverterRegistry converterRegistry) {
+ ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
+ ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
+ ConverterRegistry converterRegistry) {
if (reflectionProvider == null) {
reflectionProvider = JVM.newReflectionProvider();
}
this.reflectionProvider = reflectionProvider;
- hierarchicalStreamDriver = driver;
+ this.hierarchicalStreamDriver = driver;
this.classLoaderReference = classLoaderReference;
this.converterLookup = converterLookup;
this.converterRegistry = converterRegistry;
@@ -560,96 +602,199 @@
mapper = new DynamicProxyMapper(mapper);
mapper = new PackageAliasingMapper(mapper);
mapper = new ClassAliasingMapper(mapper);
+ mapper = new ElementIgnoringMapper(mapper);
mapper = new FieldAliasingMapper(mapper);
mapper = new AttributeAliasingMapper(mapper);
mapper = new SystemAttributeAliasingMapper(mapper);
- mapper = new ImplicitCollectionMapper(mapper);
+ mapper = new ImplicitCollectionMapper(mapper, reflectionProvider);
mapper = new OuterClassMapper(mapper);
mapper = new ArrayMapper(mapper);
mapper = new DefaultImplementationsMapper(mapper);
mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider);
- mapper = new EnumMapper(mapper);
+ if (JVM.is15()) {
+ mapper = buildMapperDynamically(
+ "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
+ new Object[]{mapper});
+ }
mapper = new LocalConversionMapper(mapper);
mapper = new ImmutableTypesMapper(mapper);
+ if (JVM.is18()) {
+ mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class},
+ new Object[]{mapper});
+ }
mapper = new SecurityMapper(mapper);
- mapper = new AnnotationMapper(mapper, converterRegistry, converterLookup, classLoaderReference,
- reflectionProvider);
+ if (JVM.is15()) {
+ mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{
+ Mapper.class, ConverterRegistry.class, ConverterLookup.class,
+ ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{
+ mapper, converterRegistry, converterLookup, classLoaderReference,
+ reflectionProvider});
+ }
mapper = wrapMapper((MapperWrapper)mapper);
mapper = new CachingMapper(mapper);
return mapper;
}
- @SuppressWarnings("unused")
- private Mapper buildMapperDynamically(final String className, final Class>[] constructorParamTypes,
- final Object[] constructorParamValues) {
+ private Mapper buildMapperDynamically(String className, Class[] constructorParamTypes,
+ Object[] constructorParamValues) {
try {
- final Class> type = Class.forName(className, false, classLoaderReference.getReference());
- final Constructor> constructor = type.getConstructor(constructorParamTypes);
+ Class type = Class.forName(className, false, classLoaderReference.getReference());
+ Constructor constructor = type.getConstructor(constructorParamTypes);
return (Mapper)constructor.newInstance(constructorParamValues);
- } catch (final Exception e) {
- throw new InitializationException("Could not instantiate mapper : " + className, e);
- } catch (final LinkageError e) {
- throw new InitializationException("Could not instantiate mapper : " + className, e);
+ } catch (Exception e) {
+ throw new com.thoughtworks.xstream.InitializationException(
+ "Could not instantiate mapper : " + className, e);
+ } catch (LinkageError e) {
+ throw new com.thoughtworks.xstream.InitializationException(
+ "Could not instantiate mapper : " + className, e);
}
}
- protected MapperWrapper wrapMapper(final MapperWrapper next) {
+ protected MapperWrapper wrapMapper(MapperWrapper next) {
return next;
}
/**
- * @deprecated As of upcoming
+ * @deprecated As of 1.4.8
*/
- @Deprecated
protected boolean useXStream11XmlFriendlyMapper() {
return false;
}
private void setupMappers() {
- packageAliasingMapper = mapper.lookupMapperOfType(PackageAliasingMapper.class);
- classAliasingMapper = mapper.lookupMapperOfType(ClassAliasingMapper.class);
- fieldAliasingMapper = mapper.lookupMapperOfType(FieldAliasingMapper.class);
- attributeMapper = mapper.lookupMapperOfType(AttributeMapper.class);
- attributeAliasingMapper = mapper.lookupMapperOfType(AttributeAliasingMapper.class);
- systemAttributeAliasingMapper = mapper.lookupMapperOfType(SystemAttributeAliasingMapper.class);
- implicitCollectionMapper = mapper.lookupMapperOfType(ImplicitCollectionMapper.class);
- defaultImplementationsMapper = mapper.lookupMapperOfType(DefaultImplementationsMapper.class);
- immutableTypesMapper = mapper.lookupMapperOfType(ImmutableTypesMapper.class);
- localConversionMapper = mapper.lookupMapperOfType(LocalConversionMapper.class);
- securityMapper = mapper.lookupMapperOfType(SecurityMapper.class);
- annotationMapper = mapper.lookupMapperOfType(AnnotationMapper.class);
+ packageAliasingMapper = (PackageAliasingMapper)this.mapper
+ .lookupMapperOfType(PackageAliasingMapper.class);
+ classAliasingMapper = (ClassAliasingMapper)this.mapper
+ .lookupMapperOfType(ClassAliasingMapper.class);
+ elementIgnoringMapper = (ElementIgnoringMapper)this.mapper
+ .lookupMapperOfType(ElementIgnoringMapper.class);
+ fieldAliasingMapper = (FieldAliasingMapper)this.mapper
+ .lookupMapperOfType(FieldAliasingMapper.class);
+ attributeMapper = (AttributeMapper)this.mapper
+ .lookupMapperOfType(AttributeMapper.class);
+ attributeAliasingMapper = (AttributeAliasingMapper)this.mapper
+ .lookupMapperOfType(AttributeAliasingMapper.class);
+ systemAttributeAliasingMapper = (SystemAttributeAliasingMapper)this.mapper
+ .lookupMapperOfType(SystemAttributeAliasingMapper.class);
+ implicitCollectionMapper = (ImplicitCollectionMapper)this.mapper
+ .lookupMapperOfType(ImplicitCollectionMapper.class);
+ defaultImplementationsMapper = (DefaultImplementationsMapper)this.mapper
+ .lookupMapperOfType(DefaultImplementationsMapper.class);
+ immutableTypesMapper = (ImmutableTypesMapper)this.mapper
+ .lookupMapperOfType(ImmutableTypesMapper.class);
+ localConversionMapper = (LocalConversionMapper)this.mapper
+ .lookupMapperOfType(LocalConversionMapper.class);
+ securityMapper = (SecurityMapper)this.mapper
+ .lookupMapperOfType(SecurityMapper.class);
+ annotationConfiguration = (AnnotationConfiguration)this.mapper
+ .lookupMapperOfType(AnnotationConfiguration.class);
}
-
+
protected void setupSecurity() {
if (securityMapper == null) {
return;
}
+
+ addPermission(AnyTypePermission.ANY);
+ insecureWarning = true;
+ }
- addPermission(NullPermission.NULL);
- addPermission(PrimitiveTypePermission.PRIMITIVES);
- addPermission(ArrayTypePermission.ARRAYS);
- addPermission(InterfaceTypePermission.INTERFACES);
- allowTypeHierarchy(Calendar.class);
- allowTypeHierarchy(Collection.class);
- allowTypeHierarchy(Enum.class);
- allowTypeHierarchy(Map.class);
- allowTypeHierarchy(Map.Entry.class);
- allowTypeHierarchy(Member.class);
- allowTypeHierarchy(Number.class);
- allowTypeHierarchy(Throwable.class);
- allowTypeHierarchy(TimeZone.class);
+ /**
+ * Setup the security framework of a XStream instance.
+ *
+ * This method is a pure helper method for XStream 1.4.x. It initializes an XStream instance with a white list of
+ * well-known and simply types of the Java runtime as it is done in XStream 1.5.x by default. This method will do
+ * therefore nothing in XStream 1.5.
+ *
+ *
+ * @param xstream
+ * @since 1.4.10
+ */
+ public static void setupDefaultSecurity(final XStream xstream) {
+ if (xstream.insecureWarning) {
+ xstream.addPermission(NoTypePermission.NONE);
+ xstream.addPermission(NullPermission.NULL);
+ xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
+ xstream.addPermission(ArrayTypePermission.ARRAYS);
+ xstream.addPermission(InterfaceTypePermission.INTERFACES);
+ xstream.allowTypeHierarchy(Calendar.class);
+ xstream.allowTypeHierarchy(Collection.class);
+ xstream.allowTypeHierarchy(Map.class);
+ xstream.allowTypeHierarchy(Map.Entry.class);
+ xstream.allowTypeHierarchy(Member.class);
+ xstream.allowTypeHierarchy(Number.class);
+ xstream.allowTypeHierarchy(Throwable.class);
+ xstream.allowTypeHierarchy(TimeZone.class);
- final Set> types = new HashSet>();
- types.addAll(Arrays.>asList(BitSet.class, Charset.class, Class.class, Currency.class, Date.class,
- DecimalFormatSymbols.class, File.class, Locale.class, Object.class, Pattern.class, StackTraceElement.class,
- String.class, StringBuffer.class, StringBuilder.class, URL.class, URI.class, UUID.class));
- if (JVM.isSQLAvailable()) {
- types.add(JVM.loadClassForName("java.sql.Timestamp"));
- types.add(JVM.loadClassForName("java.sql.Time"));
- types.add(JVM.loadClassForName("java.sql.Date"));
+ Class type = JVM.loadClassForName("java.lang.Enum");
+ if (type != null) {
+ xstream.allowTypeHierarchy(type);
+ }
+ type = JVM.loadClassForName("java.nio.file.Path");
+ if (type != null) {
+ xstream.allowTypeHierarchy(type);
+ }
+
+ final Set types = new HashSet();
+ types.add(BitSet.class);
+ types.add(Charset.class);
+ types.add(Class.class);
+ types.add(Currency.class);
+ types.add(Date.class);
+ types.add(DecimalFormatSymbols.class);
+ types.add(File.class);
+ types.add(Locale.class);
+ types.add(Object.class);
+ types.add(Pattern.class);
+ types.add(StackTraceElement.class);
+ types.add(String.class);
+ types.add(StringBuffer.class);
+ types.add(JVM.loadClassForName("java.lang.StringBuilder"));
+ types.add(URL.class);
+ types.add(URI.class);
+ types.add(JVM.loadClassForName("java.util.UUID"));
+ if (JVM.isSQLAvailable()) {
+ types.add(JVM.loadClassForName("java.sql.Timestamp"));
+ types.add(JVM.loadClassForName("java.sql.Time"));
+ types.add(JVM.loadClassForName("java.sql.Date"));
+ }
+ if (JVM.is18()) {
+ xstream.allowTypeHierarchy(JVM.loadClassForName("java.time.Clock"));
+ types.add(JVM.loadClassForName("java.time.Duration"));
+ types.add(JVM.loadClassForName("java.time.Instant"));
+ types.add(JVM.loadClassForName("java.time.LocalDate"));
+ types.add(JVM.loadClassForName("java.time.LocalDateTime"));
+ types.add(JVM.loadClassForName("java.time.LocalTime"));
+ types.add(JVM.loadClassForName("java.time.MonthDay"));
+ types.add(JVM.loadClassForName("java.time.OffsetDateTime"));
+ types.add(JVM.loadClassForName("java.time.OffsetTime"));
+ types.add(JVM.loadClassForName("java.time.Period"));
+ types.add(JVM.loadClassForName("java.time.Ser"));
+ types.add(JVM.loadClassForName("java.time.Year"));
+ types.add(JVM.loadClassForName("java.time.YearMonth"));
+ types.add(JVM.loadClassForName("java.time.ZonedDateTime"));
+ xstream.allowTypeHierarchy(JVM.loadClassForName("java.time.ZoneId"));
+ types.add(JVM.loadClassForName("java.time.chrono.HijrahDate"));
+ types.add(JVM.loadClassForName("java.time.chrono.JapaneseDate"));
+ types.add(JVM.loadClassForName("java.time.chrono.JapaneseEra"));
+ types.add(JVM.loadClassForName("java.time.chrono.MinguoDate"));
+ types.add(JVM.loadClassForName("java.time.chrono.ThaiBuddhistDate"));
+ types.add(JVM.loadClassForName("java.time.chrono.Ser"));
+ xstream.allowTypeHierarchy(JVM.loadClassForName("java.time.chrono.Chronology"));
+ types.add(JVM.loadClassForName("java.time.temporal.ValueRange"));
+ types.add(JVM.loadClassForName("java.time.temporal.WeekFields"));
+ }
+ types.remove(null);
+
+ final Iterator iter = types.iterator();
+ final Class[] classes = new Class[types.size()];
+ for (int i = 0; i < classes.length; ++i) {
+ classes[i] = (Class)iter.next();
+ }
+ xstream.allowTypes(classes);
+ } else {
+ throw new IllegalArgumentException("Security framework of XStream instance already initialized");
}
- types.remove(null);
- allowTypes(types.toArray(new Class[types.size()]));
}
protected void setupAliases() {
@@ -671,23 +816,16 @@
alias("big-int", BigInteger.class);
alias("big-decimal", BigDecimal.class);
- alias("string", String.class);
alias("string-buffer", StringBuffer.class);
- alias("string-builder", StringBuilder.class);
- alias("uuid", UUID.class);
+ alias("string", String.class);
alias("java-class", Class.class);
alias("method", Method.class);
alias("constructor", Constructor.class);
alias("field", Field.class);
alias("date", Date.class);
- alias("gregorian-calendar", Calendar.class);
alias("uri", URI.class);
alias("url", URL.class);
- alias("file", File.class);
- alias("locale", Locale.class);
alias("bit-set", BitSet.class);
- alias("trace", StackTraceElement.class);
- alias("currency", Currency.class);
alias("map", Map.class);
alias("entry", Map.Entry.class);
@@ -701,12 +839,7 @@
alias("tree-map", TreeMap.class);
alias("tree-set", TreeSet.class);
alias("hashtable", Hashtable.class);
- alias("linked-hash-map", LinkedHashMap.class);
- alias("linked-hash-set", LinkedHashSet.class);
- alias("concurrent-hash-map", ConcurrentHashMap.class);
-
- alias("enum-set", EnumSet.class);
- alias("enum-map", EnumMap.class);
+
alias("empty-list", Collections.EMPTY_LIST.getClass());
alias("empty-map", Collections.EMPTY_MAP.getClass());
alias("empty-set", Collections.EMPTY_SET.getClass());
@@ -723,24 +856,88 @@
alias("awt-text-attribute", JVM.loadClassForName("java.awt.font.TextAttribute"));
}
+ Class type = JVM.loadClassForName("javax.activation.ActivationDataFlavor");
+ if (type != null) {
+ alias("activation-data-flavor", type);
+ }
+
if (JVM.isSQLAvailable()) {
alias("sql-timestamp", JVM.loadClassForName("java.sql.Timestamp"));
alias("sql-time", JVM.loadClassForName("java.sql.Time"));
alias("sql-date", JVM.loadClassForName("java.sql.Date"));
}
- aliasType("charset", Charset.class);
+ alias("file", File.class);
+ alias("locale", Locale.class);
+ alias("gregorian-calendar", Calendar.class);
- if (JVM.loadClassForName("javax.security.auth.Subject") != null) {
+ if (JVM.is14()) {
aliasDynamically("auth-subject", "javax.security.auth.Subject");
+ alias("linked-hash-map", JVM.loadClassForName("java.util.LinkedHashMap"));
+ alias("linked-hash-set", JVM.loadClassForName("java.util.LinkedHashSet"));
+ alias("trace", JVM.loadClassForName("java.lang.StackTraceElement"));
+ alias("currency", JVM.loadClassForName("java.util.Currency"));
+ aliasType("charset", JVM.loadClassForName("java.nio.charset.Charset"));
}
- if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) {
- aliasDynamically("duration", "javax.xml.datatype.Duration");
+
+ if (JVM.is15()) {
+ aliasDynamically("xml-duration", "javax.xml.datatype.Duration");
+ alias("concurrent-hash-map", JVM.loadClassForName("java.util.concurrent.ConcurrentHashMap"));
+ alias("enum-set", JVM.loadClassForName("java.util.EnumSet"));
+ alias("enum-map", JVM.loadClassForName("java.util.EnumMap"));
+ alias("string-builder", JVM.loadClassForName("java.lang.StringBuilder"));
+ alias("uuid", JVM.loadClassForName("java.util.UUID"));
}
+
+ if (JVM.is17()) {
+ aliasType("path", JVM.loadClassForName("java.nio.file.Path"));
+ }
+
+ if (JVM.is18()) {
+ alias("fixed-clock", JVM.loadClassForName("java.time.Clock$FixedClock"));
+ alias("offset-clock", JVM.loadClassForName("java.time.Clock$OffsetClock"));
+ alias("system-clock", JVM.loadClassForName("java.time.Clock$SystemClock"));
+ alias("tick-clock", JVM.loadClassForName("java.time.Clock$TickClock"));
+ alias("day-of-week", JVM.loadClassForName("java.time.DayOfWeek"));
+ alias("duration", JVM.loadClassForName("java.time.Duration"));
+ alias("instant", JVM.loadClassForName("java.time.Instant"));
+ alias("local-date", JVM.loadClassForName("java.time.LocalDate"));
+ alias("local-date-time", JVM.loadClassForName("java.time.LocalDateTime"));
+ alias("local-time", JVM.loadClassForName("java.time.LocalTime"));
+ alias("month", JVM.loadClassForName("java.time.Month"));
+ alias("month-day", JVM.loadClassForName("java.time.MonthDay"));
+ alias("offset-date-time", JVM.loadClassForName("java.time.OffsetDateTime"));
+ alias("offset-time", JVM.loadClassForName("java.time.OffsetTime"));
+ alias("period", JVM.loadClassForName("java.time.Period"));
+ alias("year", JVM.loadClassForName("java.time.Year"));
+ alias("year-month", JVM.loadClassForName("java.time.YearMonth"));
+ alias("zoned-date-time", JVM.loadClassForName("java.time.ZonedDateTime"));
+ aliasType("zone-id", JVM.loadClassForName("java.time.ZoneId"));
+ aliasType("chronology", JVM.loadClassForName("java.time.chrono.Chronology"));
+ alias("hijrah-date", JVM.loadClassForName("java.time.chrono.HijrahDate"));
+ alias("hijrah-era", JVM.loadClassForName("java.time.chrono.HijrahEra"));
+ alias("japanese-date", JVM.loadClassForName("java.time.chrono.JapaneseDate"));
+ alias("japanese-era", JVM.loadClassForName("java.time.chrono.JapaneseEra"));
+ alias("minguo-date", JVM.loadClassForName("java.time.chrono.MinguoDate"));
+ alias("minguo-era", JVM.loadClassForName("java.time.chrono.MinguoEra"));
+ alias("thai-buddhist-date", JVM.loadClassForName("java.time.chrono.ThaiBuddhistDate"));
+ alias("thai-buddhist-era", JVM.loadClassForName("java.time.chrono.ThaiBuddhistEra"));
+ alias("chrono-field", JVM.loadClassForName("java.time.temporal.ChronoField"));
+ alias("chrono-unit", JVM.loadClassForName("java.time.temporal.ChronoUnit"));
+ alias("iso-field", JVM.loadClassForName("java.time.temporal.IsoFields$Field"));
+ alias("iso-unit", JVM.loadClassForName("java.time.temporal.IsoFields$Unit"));
+ alias("julian-field", JVM.loadClassForName("java.time.temporal.JulianFields$Field"));
+ alias("temporal-value-range", JVM.loadClassForName("java.time.temporal.ValueRange"));
+ alias("week-fields", JVM.loadClassForName("java.time.temporal.WeekFields"));
+ }
+
+ if (JVM.loadClassForName("java.lang.invoke.SerializedLambda") != null) {
+ aliasDynamically("serialized-lambda", "java.lang.invoke.SerializedLambda");
+ }
}
- private void aliasDynamically(final String alias, final String className) {
- final Class> type = JVM.loadClassForName(className);
+ private void aliasDynamically(String alias, String className) {
+ Class type = JVM.loadClassForName(className);
if (type != null) {
alias(alias, type);
}
@@ -758,10 +955,13 @@
}
protected void setupConverters() {
- registerConverter(new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
+ registerConverter(
+ new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
- registerConverter(new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
+ registerConverter(
+ new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
registerConverter(new ExternalizableConverter(mapper, classLoaderReference), PRIORITY_LOW);
+ registerConverter(new InternalBlackList(), PRIORITY_LOW);
registerConverter(new NullConverter(), PRIORITY_VERY_HIGH);
registerConverter(new IntConverter(), PRIORITY_NORMAL);
@@ -775,17 +975,8 @@
registerConverter(new StringConverter(), PRIORITY_NORMAL);
registerConverter(new StringBufferConverter(), PRIORITY_NORMAL);
- registerConverter(new StringBuilderConverter(), PRIORITY_NORMAL);
- registerConverter(new ThrowableConverter(converterLookup), PRIORITY_NORMAL);
- registerConverter(new StackTraceElementConverter(), PRIORITY_NORMAL);
registerConverter(new DateConverter(), PRIORITY_NORMAL);
- registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL);
- registerConverter(new RegexPatternConverter(), PRIORITY_NORMAL);
- registerConverter(new CurrencyConverter(), PRIORITY_NORMAL);
- registerConverter(new CharsetConverter(), PRIORITY_NORMAL);
- registerConverter(new LocaleConverter(), PRIORITY_NORMAL);
registerConverter(new BitSetConverter(), PRIORITY_NORMAL);
- registerConverter(new UUIDConverter(), PRIORITY_NORMAL);
registerConverter(new URIConverter(), PRIORITY_NORMAL);
registerConverter(new URLConverter(), PRIORITY_NORMAL);
registerConverter(new BigIntegerConverter(), PRIORITY_NORMAL);
@@ -801,9 +992,6 @@
registerConverter(new SingletonMapConverter(mapper), PRIORITY_NORMAL);
registerConverter(new PropertiesConverter(), PRIORITY_NORMAL);
registerConverter((Converter)new EncodedByteArrayConverter(), PRIORITY_NORMAL);
- registerConverter(new EnumConverter(), PRIORITY_NORMAL);
- registerConverter(new EnumSetConverter(mapper), PRIORITY_NORMAL);
- registerConverter(new EnumMapConverter(mapper), PRIORITY_NORMAL);
registerConverter(new FileConverter(), PRIORITY_NORMAL);
if (JVM.isSQLAvailable()) {
@@ -815,42 +1003,144 @@
registerConverter(new JavaClassConverter(classLoaderReference), PRIORITY_NORMAL);
registerConverter(new JavaMethodConverter(classLoaderReference), PRIORITY_NORMAL);
registerConverter(new JavaFieldConverter(classLoaderReference), PRIORITY_NORMAL);
+
if (JVM.isAWTAvailable()) {
registerConverter(new FontConverter(mapper), PRIORITY_NORMAL);
registerConverter(new ColorConverter(), PRIORITY_NORMAL);
registerConverter(new TextAttributeConverter(), PRIORITY_NORMAL);
}
if (JVM.isSwingAvailable()) {
- registerConverter(new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
+ registerConverter(
+ new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
}
+ registerConverter(new LocaleConverter(), PRIORITY_NORMAL);
+ registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL);
- if (JVM.loadClassForName("javax.security.auth.Subject") != null) {
- registerConverterDynamically("com.thoughtworks.xstream.converters.extended.SubjectConverter",
+ if (JVM.is14()) {
+ // late bound converters - allows XStream to be compiled on earlier JDKs
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.SubjectConverter",
PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.ThrowableConverter",
+ PRIORITY_NORMAL, new Class[]{ConverterLookup.class},
+ new Object[]{converterLookup});
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.StackTraceElementConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.CurrencyConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.RegexPatternConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.CharsetConverter",
+ PRIORITY_NORMAL, null, null);
}
- if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) {
- registerConverterDynamically("com.thoughtworks.xstream.converters.extended.DurationConverter",
+
+ if (JVM.is15()) {
+ // late bound converters - allows XStream to be compiled on earlier JDKs
+ if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) {
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.extended.DurationConverter",
+ PRIORITY_NORMAL, null, null);
+ }
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL,
+ new Class[]{Mapper.class}, new Object[]{mapper});
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL,
+ new Class[]{Mapper.class}, new Object[]{mapper});
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.basic.StringBuilderConverter",
PRIORITY_NORMAL, null, null);
+ registerConverterDynamically(
+ "com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
+ null, null);
}
+ if (JVM.loadClassForName("javax.activation.ActivationDataFlavor") != null) {
+ registerConverterDynamically("com.thoughtworks.xstream.converters.extended.ActivationDataFlavorConverter",
+ PRIORITY_NORMAL, null, null);
+ }
+ if (JVM.is17()) {
+ registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter",
+ PRIORITY_NORMAL, null, null);
+ }
+ if (JVM.is18()) {
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.ChronologyConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.DurationConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.HijrahDateConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.JapaneseDateConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.JapaneseEraConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.InstantConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.LocalDateConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.LocalDateTimeConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.LocalTimeConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.MinguoDateConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.MonthDayConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.OffsetDateTimeConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.OffsetTimeConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.PeriodConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.SystemClockConverter",
+ PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.ThaiBuddhistDateConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.ValueRangeConverter",
+ PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.WeekFieldsConverter",
+ PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.YearConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.YearMonthConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.ZonedDateTimeConverter",
+ PRIORITY_NORMAL, null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.time.ZoneIdConverter", PRIORITY_NORMAL,
+ null, null);
+ registerConverterDynamically("com.thoughtworks.xstream.converters.reflection.LambdaConverter",
+ PRIORITY_NORMAL, new Class[]{Mapper.class, ReflectionProvider.class, ClassLoaderReference.class},
+ new Object[]{mapper, reflectionProvider, classLoaderReference});
+ }
- registerConverter(new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
+ registerConverter(
+ new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
}
- private void registerConverterDynamically(final String className, final int priority,
- final Class>[] constructorParamTypes, final Object[] constructorParamValues) {
+ private void registerConverterDynamically(String className, int priority,
+ Class[] constructorParamTypes, Object[] constructorParamValues) {
try {
- final Class> type = Class.forName(className, false, classLoaderReference.getReference());
- final Constructor> constructor = type.getConstructor(constructorParamTypes);
- final Object instance = constructor.newInstance(constructorParamValues);
+ Class type = Class.forName(className, false, classLoaderReference.getReference());
+ Constructor constructor = type.getConstructor(constructorParamTypes);
+ Object instance = constructor.newInstance(constructorParamValues);
if (instance instanceof Converter) {
registerConverter((Converter)instance, priority);
} else if (instance instanceof SingleValueConverter) {
registerConverter((SingleValueConverter)instance, priority);
}
- } catch (final Exception e) {
- throw new InitializationException("Could not instantiate converter : " + className, e);
- } catch (final LinkageError e) {
- throw new InitializationException("Could not instantiate converter : " + className, e);
+ } catch (Exception e) {
+ throw new com.thoughtworks.xstream.InitializationException(
+ "Could not instantiate converter : " + className, e);
+ } catch (LinkageError e) {
+ throw new com.thoughtworks.xstream.InitializationException(
+ "Could not instantiate converter : " + className, e);
}
}
@@ -860,81 +1150,133 @@
}
// primitives are always immutable
- addImmutableType(boolean.class);
- addImmutableType(Boolean.class);
- addImmutableType(byte.class);
- addImmutableType(Byte.class);
- addImmutableType(char.class);
- addImmutableType(Character.class);
- addImmutableType(double.class);
- addImmutableType(Double.class);
- addImmutableType(float.class);
- addImmutableType(Float.class);
- addImmutableType(int.class);
- addImmutableType(Integer.class);
- addImmutableType(long.class);
- addImmutableType(Long.class);
- addImmutableType(short.class);
- addImmutableType(Short.class);
+ addImmutableType(boolean.class, false);
+ addImmutableType(Boolean.class, false);
+ addImmutableType(byte.class, false);
+ addImmutableType(Byte.class, false);
+ addImmutableType(char.class, false);
+ addImmutableType(Character.class, false);
+ addImmutableType(double.class, false);
+ addImmutableType(Double.class, false);
+ addImmutableType(float.class, false);
+ addImmutableType(Float.class, false);
+ addImmutableType(int.class, false);
+ addImmutableType(Integer.class, false);
+ addImmutableType(long.class, false);
+ addImmutableType(Long.class, false);
+ addImmutableType(short.class, false);
+ addImmutableType(Short.class, false);
// additional types
- addImmutableType(Mapper.Null.class);
- addImmutableType(BigDecimal.class);
- addImmutableType(BigInteger.class);
- addImmutableType(String.class);
- addImmutableType(Charset.class);
- addImmutableType(Currency.class);
- addImmutableType(URI.class);
- addImmutableType(URL.class);
- addImmutableType(File.class);
- addImmutableType(Class.class);
+ addImmutableType(Mapper.Null.class, false);
+ addImmutableType(BigDecimal.class, false);
+ addImmutableType(BigInteger.class, false);
+ addImmutableType(String.class, false);
+ addImmutableType(URL.class, false);
+ addImmutableType(File.class, false);
+ addImmutableType(Class.class, false);
- addImmutableType(Collections.EMPTY_LIST.getClass());
- addImmutableType(Collections.EMPTY_SET.getClass());
- addImmutableType(Collections.EMPTY_MAP.getClass());
+ if (JVM.is17()) {
+ Class type = JVM.loadClassForName("java.nio.file.Paths");
+ if (type != null) {
+ Method methodGet;
+ try {
+ methodGet = type.getDeclaredMethod("get", new Class[] {String.class, String[].class});
+ if (methodGet != null) {
+ Object path = methodGet.invoke(null, new Object[]{".", new String[0]});
+ if (path != null) {
+ addImmutableType(path.getClass(), false);
+ }
+ }
+ } catch (NoSuchMethodException e) {
+ } catch (SecurityException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ }
+ }
if (JVM.isAWTAvailable()) {
- addImmutableTypeDynamically("java.awt.font.TextAttribute");
+ addImmutableTypeDynamically("java.awt.font.TextAttribute", false);
}
+
+ if (JVM.is14()) {
+ // late bound types - allows XStream to be compiled on earlier JDKs
+ addImmutableTypeDynamically("java.nio.charset.Charset", true);
+ addImmutableTypeDynamically("java.util.Currency", true);
+ }
+
+ if (JVM.is15()) {
+ addImmutableTypeDynamically("java.util.UUID", true);
+ }
+
+ addImmutableType(URI.class, true);
+ addImmutableType(Collections.EMPTY_LIST.getClass(), true);
+ addImmutableType(Collections.EMPTY_SET.getClass(), true);
+ addImmutableType(Collections.EMPTY_MAP.getClass(), true);
+
+ if (JVM.is18()) {
+ addImmutableTypeDynamically("java.time.Duration", false);
+ addImmutableTypeDynamically("java.time.Instant", false);
+ addImmutableTypeDynamically("java.time.LocalDate", false);
+ addImmutableTypeDynamically("java.time.LocalDateTime", false);
+ addImmutableTypeDynamically("java.time.LocalTime", false);
+ addImmutableTypeDynamically("java.time.MonthDay", false);
+ addImmutableTypeDynamically("java.time.OffsetDateTime", false);
+ addImmutableTypeDynamically("java.time.OffsetTime", false);
+ addImmutableTypeDynamically("java.time.Period", false);
+ addImmutableTypeDynamically("java.time.Year", false);
+ addImmutableTypeDynamically("java.time.YearMonth", false);
+ addImmutableTypeDynamically("java.time.ZonedDateTime", false);
+ addImmutableTypeDynamically("java.time.ZoneId", false);
+ addImmutableTypeDynamically("java.time.ZoneOffset", false);
+ addImmutableTypeDynamically("java.time.ZoneRegion", false);
+ addImmutableTypeDynamically("java.time.chrono.HijrahChronology", false);
+ addImmutableTypeDynamically("java.time.chrono.HijrahDate", false);
+ addImmutableTypeDynamically("java.time.chrono.IsoChronology", false);
+ addImmutableTypeDynamically("java.time.chrono.JapaneseChronology", false);
+ addImmutableTypeDynamically("java.time.chrono.JapaneseDate", false);
+ addImmutableTypeDynamically("java.time.chrono.JapaneseEra", false);
+ addImmutableTypeDynamically("java.time.chrono.MinguoChronology", false);
+ addImmutableTypeDynamically("java.time.chrono.MinguoDate", false);
+ addImmutableTypeDynamically("java.time.chrono.ThaiBuddhistChronology", false);
+ addImmutableTypeDynamically("java.time.chrono.ThaiBuddhistDate", false);
+ addImmutableTypeDynamically("java.time.temporal.IsoFields$Field", false);
+ addImmutableTypeDynamically("java.time.temporal.IsoFields$Unit", false);
+ addImmutableTypeDynamically("java.time.temporal.JulianFields$Field", false);
+ }
}
- private void addImmutableTypeDynamically(final String className) {
- final Class> type = JVM.loadClassForName(className);
+ private void addImmutableTypeDynamically(String className, boolean isReferenceable) {
+ Class type = JVM.loadClassForName(className);
if (type != null) {
- addImmutableType(type);
+ addImmutableType(type, isReferenceable);
}
}
- /**
- * Setter for an arbitrary marshalling strategy.
- *
- * @param marshallingStrategy the implementation to use
- * @see #setMode(int)
- */
- public void setMarshallingStrategy(final MarshallingStrategy marshallingStrategy) {
+ public void setMarshallingStrategy(MarshallingStrategy marshallingStrategy) {
this.marshallingStrategy = marshallingStrategy;
}
/**
* Serialize an object to a pretty-printed XML String.
- *
+ *
* @throws XStreamException if the object cannot be serialized
*/
- public String toXML(final Object obj) {
- final Writer writer = new StringWriter();
+ public String toXML(Object obj) {
+ Writer writer = new StringWriter();
toXML(obj, writer);
return writer.toString();
}
/**
- * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed afterwards and in case
- * of an exception.
+ * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed
+ * afterwards and in case of an exception.
*
* @throws XStreamException if the object cannot be serialized
*/
- public void toXML(final Object obj, final Writer out) {
- @SuppressWarnings("resource")
- final HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
+ public void toXML(Object obj, Writer out) {
+ HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
try {
marshal(obj, writer);
} finally {
@@ -943,14 +1285,13 @@
}
/**
- * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream will be flushed afterwards
- * and in case of an exception.
+ * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream
+ * will be flushed afterwards and in case of an exception.
*
* @throws XStreamException if the object cannot be serialized
*/
- public void toXML(final Object obj, final OutputStream out) {
- @SuppressWarnings("resource")
- final HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
+ public void toXML(Object obj, OutputStream out) {
+ HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
try {
marshal(obj, writer);
} finally {
@@ -960,119 +1301,131 @@
/**
* Serialize and object to a hierarchical data structure (such as XML).
- *
+ *
* @throws XStreamException if the object cannot be serialized
*/
- public void marshal(final Object obj, final HierarchicalStreamWriter writer) {
+ public void marshal(Object obj, HierarchicalStreamWriter writer) {
marshal(obj, writer, null);
}
/**
* Serialize and object to a hierarchical data structure (such as XML).
*
- * @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
- * XStream shall create one lazily as needed.
+ * @param dataHolder Extra data you can use to pass to your converters. Use this as you
+ * want. If not present, XStream shall create one lazily as needed.
* @throws XStreamException if the object cannot be serialized
*/
- public void marshal(final Object obj, final HierarchicalStreamWriter writer, final DataHolder dataHolder) {
+ public void marshal(Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder) {
marshallingStrategy.marshal(writer, obj, converterLookup, mapper, dataHolder);
}
/**
* Deserialize an object from an XML String.
- *
+ *
* @throws XStreamException if the object cannot be deserialized
*/
- public T fromXML(final String xml) {
+ public Object fromXML(String xml) {
return fromXML(new StringReader(xml));
}
/**
* Deserialize an object from an XML Reader.
- *
+ *
* @throws XStreamException if the object cannot be deserialized
*/
- public T fromXML(final Reader reader) {
+ public Object fromXML(Reader reader) {
return unmarshal(hierarchicalStreamDriver.createReader(reader), null);
}
/**
* Deserialize an object from an XML InputStream.
- *
+ *
* @throws XStreamException if the object cannot be deserialized
*/
- public T fromXML(final InputStream input) {
+ public Object fromXML(InputStream input) {
return unmarshal(hierarchicalStreamDriver.createReader(input), null);
}
/**
- * Deserialize an object from a URL. Depending on the parser implementation, some might take the file path as
- * SystemId to resolve additional references.
+ * Deserialize an object from a URL.
*
+ * Depending on the parser implementation, some might take the file path as SystemId to
+ * resolve additional references.
+ *
* @throws XStreamException if the object cannot be deserialized
* @since 1.4
*/
- public T fromXML(final URL url) {
+ public Object fromXML(URL url) {
return fromXML(url, null);
}
/**
- * Deserialize an object from a file. Depending on the parser implementation, some might take the file path as
- * SystemId to resolve additional references.
+ * Deserialize an object from a file.
*
+ * Depending on the parser implementation, some might take the file path as SystemId to
+ * resolve additional references.
+ *
* @throws XStreamException if the object cannot be deserialized
* @since 1.4
*/
- public T fromXML(final File file) {
+ public Object fromXML(File file) {
return fromXML(file, null);
}
/**
- * Deserialize an object from an XML String, populating the fields of the given root object instead of instantiating
- * a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into
- * the raw memory area of the existing object. Use with care!
+ * Deserialize an object from an XML String, populating the fields of the given root object
+ * instead of instantiating a new one. Note, that this is a special use case! With the
+ * ReflectionConverter XStream will write directly into the raw memory area of the existing
+ * object. Use with care!
*
* @throws XStreamException if the object cannot be deserialized
*/
- public T fromXML(final String xml, final T root) {
+ public Object fromXML(String xml, Object root) {
return fromXML(new StringReader(xml), root);
}
/**
- * Deserialize an object from an XML Reader, populating the fields of the given root object instead of instantiating
- * a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into
- * the raw memory area of the existing object. Use with care!
+ * Deserialize an object from an XML Reader, populating the fields of the given root object
+ * instead of instantiating a new one. Note, that this is a special use case! With the
+ * ReflectionConverter XStream will write directly into the raw memory area of the existing
+ * object. Use with care!
*
* @throws XStreamException if the object cannot be deserialized
*/
- public T fromXML(final Reader xml, final T root) {
+ public Object fromXML(Reader xml, Object root) {
return unmarshal(hierarchicalStreamDriver.createReader(xml), root);
}
/**
- * Deserialize an object from a URL, populating the fields of the given root object instead of instantiating a new
- * one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
- * memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
- * file path as SystemId to resolve additional references.
+ * Deserialize an object from a URL, populating the fields of the given root
+ * object instead of instantiating a new one. Note, that this is a special use case! With
+ * the ReflectionConverter XStream will write directly into the raw memory area of the
+ * existing object. Use with care!
*
+ * Depending on the parser implementation, some might take the file path as SystemId to
+ * resolve additional references.
+ *
* @throws XStreamException if the object cannot be deserialized
* @since 1.4
*/
- public T fromXML(final URL url, final T root) {
+ public Object fromXML(URL url, Object root) {
return unmarshal(hierarchicalStreamDriver.createReader(url), root);
}
/**
- * Deserialize an object from a file, populating the fields of the given root object instead of instantiating a new
- * one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
- * memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
- * file path as SystemId to resolve additional references.
+ * Deserialize an object from a file, populating the fields of the given root
+ * object instead of instantiating a new one. Note, that this is a special use case! With
+ * the ReflectionConverter XStream will write directly into the raw memory area of the
+ * existing object. Use with care!
*
+ * Depending on the parser implementation, some might take the file path as SystemId to
+ * resolve additional references.
+ *
* @throws XStreamException if the object cannot be deserialized
* @since 1.4
*/
- public T fromXML(final File file, final T root) {
- final HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file);
+ public Object fromXML(File file, Object root) {
+ HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file);
try {
return unmarshal(reader, root);
} finally {
@@ -1081,326 +1434,357 @@
}
/**
- * Deserialize an object from an XML InputStream, populating the fields of the given root object instead of
- * instantiating a new one. Note, that this is a special use case! With the ReflectionConverter XStream will write
- * directly into the raw memory area of the existing object. Use with care!
+ * Deserialize an object from an XML InputStream, populating the fields of the given root
+ * object instead of instantiating a new one. Note, that this is a special use case! With
+ * the ReflectionConverter XStream will write directly into the raw memory area of the
+ * existing object. Use with care!
*
* @throws XStreamException if the object cannot be deserialized
*/
- public T fromXML(final InputStream input, final T root) {
+ public Object fromXML(InputStream input, Object root) {
return unmarshal(hierarchicalStreamDriver.createReader(input), root);
}
/**
* Deserialize an object from a hierarchical data structure (such as XML).
- *
+ *
* @throws XStreamException if the object cannot be deserialized
*/
- public T unmarshal(final HierarchicalStreamReader reader) {
+ public Object unmarshal(HierarchicalStreamReader reader) {
return unmarshal(reader, null, null);
}
/**
- * Deserialize an object from a hierarchical data structure (such as XML), populating the fields of the given root
- * object instead of instantiating a new one. Note, that this is a special use case! With the ReflectionConverter
- * XStream will write directly into the raw memory area of the existing object. Use with care!
+ * Deserialize an object from a hierarchical data structure (such as XML), populating the
+ * fields of the given root object instead of instantiating a new one. Note, that this is a
+ * special use case! With the ReflectionConverter XStream will write directly into the raw
+ * memory area of the existing object. Use with care!
*
* @throws XStreamException if the object cannot be deserialized
*/
- public T unmarshal(final HierarchicalStreamReader reader, final T root) {
+ public Object unmarshal(HierarchicalStreamReader reader, Object root) {
return unmarshal(reader, root, null);
}
/**
* Deserialize an object from a hierarchical data structure (such as XML).
*
- * @param root If present, the passed in object will have its fields populated, as opposed to XStream creating a new
- * instance. Note, that this is a special use case! With the ReflectionConverter XStream will write
- * directly into the raw memory area of the existing object. Use with care!
- * @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
- * XStream shall create one lazily as needed.
+ * @param root If present, the passed in object will have its fields populated, as opposed
+ * to XStream creating a new instance. Note, that this is a special use case!
+ * With the ReflectionConverter XStream will write directly into the raw memory
+ * area of the existing object. Use with care!
+ * @param dataHolder Extra data you can use to pass to your converters. Use this as you
+ * want. If not present, XStream shall create one lazily as needed.
* @throws XStreamException if the object cannot be deserialized
*/
- public T unmarshal(final HierarchicalStreamReader reader, final T root, final DataHolder dataHolder) {
+ public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
try {
- @SuppressWarnings("unchecked")
- final T t = (T)marshallingStrategy.unmarshal(root, reader, dataHolder, converterLookup, mapper);
- return t;
+ if (insecureWarning) {
+ insecureWarning = false;
+ System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable.");
+ }
+ return marshallingStrategy.unmarshal(
+ root, reader, dataHolder, converterLookup, mapper);
- } catch (final ConversionException e) {
- final Package pkg = getClass().getPackage();
- final String version = pkg != null ? pkg.getImplementationVersion() : null;
+ } catch (ConversionException e) {
+ Package pkg = getClass().getPackage();
+ String version = pkg != null ? pkg.getImplementationVersion() : null;
e.add("version", version != null ? version : "not available");
throw e;
}
}
/**
* Alias a Class to a shorter name to be used in XML elements.
- *
+ *
* @param name Short name
* @param type Type to be aliased
* @throws InitializationException if no {@link ClassAliasingMapper} is available
*/
- public void alias(final String name, final Class> type) {
+ public void alias(String name, Class type) {
if (classAliasingMapper == null) {
- throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ClassAliasingMapper.class.getName()
+ + " available");
}
classAliasingMapper.addClassAlias(name, type);
}
/**
- * Alias a type to a shorter name to be used in XML elements. Any class that is assignable to this type will be
- * aliased to the same name.
+ * Alias a type to a shorter name to be used in XML elements. Any class that is assignable
+ * to this type will be aliased to the same name.
*
* @param name Short name
* @param type Type to be aliased
* @since 1.2
* @throws InitializationException if no {@link ClassAliasingMapper} is available
*/
- public void aliasType(final String name, final Class> type) {
+ public void aliasType(String name, Class type) {
if (classAliasingMapper == null) {
- throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ClassAliasingMapper.class.getName()
+ + " available");
}
classAliasingMapper.addTypeAlias(name, type);
}
/**
* Alias a Class to a shorter name to be used in XML elements.
- *
+ *
* @param name Short name
* @param type Type to be aliased
* @param defaultImplementation Default implementation of type to use if no other specified.
- * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link ClassAliasingMapper} is
- * available
+ * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
+ * {@link ClassAliasingMapper} is available
*/
- public void alias(final String name, final Class> type, final Class> defaultImplementation) {
+ public void alias(String name, Class type, Class defaultImplementation) {
alias(name, type);
addDefaultImplementation(defaultImplementation, type);
}
/**
* Alias a package to a shorter name to be used in XML elements.
- *
+ *
* @param name Short name
* @param pkgName package to be aliased
- * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link PackageAliasingMapper} is
- * available
+ * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
+ * {@link PackageAliasingMapper} is available
* @since 1.3.1
*/
- public void aliasPackage(final String name, final String pkgName) {
+ public void aliasPackage(String name, String pkgName) {
if (packageAliasingMapper == null) {
- throw new InitializationException("No " + PackageAliasingMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + PackageAliasingMapper.class.getName()
+ + " available");
}
packageAliasingMapper.addPackageAlias(name, pkgName);
}
/**
* Create an alias for a field name.
- *
+ *
* @param alias the alias itself
* @param definedIn the type that declares the field
* @param fieldName the name of the field
* @throws InitializationException if no {@link FieldAliasingMapper} is available
*/
- public void aliasField(final String alias, final Class> definedIn, final String fieldName) {
+ public void aliasField(String alias, Class definedIn, String fieldName) {
if (fieldAliasingMapper == null) {
- throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + FieldAliasingMapper.class.getName()
+ + " available");
}
fieldAliasingMapper.addFieldAlias(alias, definedIn, fieldName);
}
/**
* Create an alias for an attribute
- *
+ *
* @param alias the alias itself
* @param attributeName the name of the attribute
* @throws InitializationException if no {@link AttributeAliasingMapper} is available
*/
- public void aliasAttribute(final String alias, final String attributeName) {
+ public void aliasAttribute(String alias, String attributeName) {
if (attributeAliasingMapper == null) {
- throw new InitializationException("No " + AttributeAliasingMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + AttributeAliasingMapper.class.getName()
+ + " available");
}
attributeAliasingMapper.addAliasFor(attributeName, alias);
}
/**
- * Create an alias for a system attribute. XStream will not write a system attribute if its alias is set to
- * null. However, this is not reversible, i.e. deserialization of the result is likely to fail
- * afterwards and will not produce an object equal to the originally written one.
+ * Create an alias for a system attribute. XStream will not write a system attribute if its
+ * alias is set to null. However, this is not reversible, i.e. deserialization
+ * of the result is likely to fail afterwards and will not produce an object equal to the
+ * originally written one.
*
* @param alias the alias itself (may be null)
* @param systemAttributeName the name of the system attribute
* @throws InitializationException if no {@link SystemAttributeAliasingMapper} is available
* @since 1.3.1
*/
- public void aliasSystemAttribute(final String alias, final String systemAttributeName) {
+ public void aliasSystemAttribute(String alias, String systemAttributeName) {
if (systemAttributeAliasingMapper == null) {
- throw new InitializationException("No " + SystemAttributeAliasingMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + SystemAttributeAliasingMapper.class.getName()
+ + " available");
}
systemAttributeAliasingMapper.addAliasFor(systemAttributeName, alias);
}
/**
* Create an alias for an attribute.
- *
+ *
* @param definedIn the type where the attribute is defined
* @param attributeName the name of the attribute
* @param alias the alias itself
* @throws InitializationException if no {@link AttributeAliasingMapper} is available
* @since 1.2.2
*/
- public void aliasAttribute(final Class> definedIn, final String attributeName, final String alias) {
+ public void aliasAttribute(Class definedIn, String attributeName, String alias) {
aliasField(alias, definedIn, attributeName);
useAttributeFor(definedIn, attributeName);
}
/**
* Use an attribute for a field or a specific type.
- *
+ *
* @param fieldName the name of the field
* @param type the Class of the type to be rendered as XML attribute
* @throws InitializationException if no {@link AttributeMapper} is available
* @since 1.2
*/
- public void useAttributeFor(final String fieldName, final Class> type) {
+ public void useAttributeFor(String fieldName, Class type) {
if (attributeMapper == null) {
- throw new InitializationException("No " + AttributeMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + AttributeMapper.class.getName()
+ + " available");
}
attributeMapper.addAttributeFor(fieldName, type);
}
/**
* Use an attribute for a field declared in a specific type.
- *
+ *
* @param fieldName the name of the field
* @param definedIn the Class containing such field
* @throws InitializationException if no {@link AttributeMapper} is available
* @since 1.2.2
*/
- public void useAttributeFor(final Class> definedIn, final String fieldName) {
+ public void useAttributeFor(Class definedIn, String fieldName) {
if (attributeMapper == null) {
- throw new InitializationException("No " + AttributeMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + AttributeMapper.class.getName()
+ + " available");
}
attributeMapper.addAttributeFor(definedIn, fieldName);
}
/**
* Use an attribute for an arbitrary type.
- *
+ *
* @param type the Class of the type to be rendered as XML attribute
* @throws InitializationException if no {@link AttributeMapper} is available
* @since 1.2
*/
- public void useAttributeFor(final Class> type) {
+ public void useAttributeFor(Class type) {
if (attributeMapper == null) {
- throw new InitializationException("No " + AttributeMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + AttributeMapper.class.getName()
+ + " available");
}
attributeMapper.addAttributeFor(type);
}
/**
- * Associate a default implementation of a class with an object. Whenever XStream encounters an instance of this
- * type, it will use the default implementation instead. For example, java.util.ArrayList is the default
- * implementation of java.util.List.
+ * Associate a default implementation of a class with an object. Whenever XStream encounters
+ * an instance of this type, it will use the default implementation instead. For example,
+ * java.util.ArrayList is the default implementation of java.util.List.
*
* @param defaultImplementation
* @param ofType
* @throws InitializationException if no {@link DefaultImplementationsMapper} is available
*/
- public void addDefaultImplementation(final Class> defaultImplementation, final Class> ofType) {
+ public void addDefaultImplementation(Class defaultImplementation, Class ofType) {
if (defaultImplementationsMapper == null) {
- throw new InitializationException("No " + DefaultImplementationsMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + DefaultImplementationsMapper.class.getName()
+ + " available");
}
defaultImplementationsMapper.addDefaultImplementation(defaultImplementation, ofType);
}
/**
* Add immutable types. The value of the instances of these types will always be written into the stream even if
+ * they appear multiple times. However, references are still supported at deserialization time.
+ *
+ * @throws InitializationException if no {@link ImmutableTypesMapper} is available
+ * @deprecated As of 1.4.9 use {@link #addImmutableType(Class, boolean)}
+ */
+ public void addImmutableType(Class type) {
+ addImmutableType(type, true);
+ }
+
+ /**
+ * Add immutable types. The value of the instances of these types will always be written into the stream even if
* they appear multiple times.
- *
+ *
+ * Note, while a reference-keeping marshaller will not write references for immutable types into the stream, a
+ * reference-keeping unmarshaller can still support such references in the stream for compatibility reasons at the
+ * expense of memory consumption. Therefore declare these types only as referenceable if your already persisted
+ * streams do contain such references. Otherwise you may waste a lot of memory during deserialization.
+ *
+ *
+ * @param isReferenceable true if support at deserialization time is required for compatibility at the
+ * cost of a higher memory footprint, false otherwise
* @throws InitializationException if no {@link ImmutableTypesMapper} is available
+ * @since 1.4.9
*/
- public void addImmutableType(final Class> type) {
+ public void addImmutableType(final Class type, final boolean isReferenceable) {
if (immutableTypesMapper == null) {
- throw new InitializationException("No " + ImmutableTypesMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ImmutableTypesMapper.class.getName()
+ + " available");
}
- immutableTypesMapper.addImmutableType(type);
+ immutableTypesMapper.addImmutableType(type, isReferenceable);
}
- /**
- * Register a converter with normal priority.
- *
- * @param converter the converter instance
- */
- public void registerConverter(final Converter converter) {
+ public void registerConverter(Converter converter) {
registerConverter(converter, PRIORITY_NORMAL);
}
- /**
- * Register a converter with chosen priority.
- *
- * @param converter the converter instance
- * @param priority the converter priority
- */
- public void registerConverter(final Converter converter, final int priority) {
+ public void registerConverter(Converter converter, int priority) {
if (converterRegistry != null) {
converterRegistry.registerConverter(converter, priority);
}
}
- /**
- * Register a single value converter with normal priority.
- *
- * @param converter the single value converter instance
- */
- public void registerConverter(final SingleValueConverter converter) {
+ public void registerConverter(SingleValueConverter converter) {
registerConverter(converter, PRIORITY_NORMAL);
}
- /**
- * Register a single converter with chosen priority.
- *
- * @param converter the single converter instance
- * @param priority the converter priority
- */
- public void registerConverter(final SingleValueConverter converter, final int priority) {
+ public void registerConverter(SingleValueConverter converter, int priority) {
if (converterRegistry != null) {
- converterRegistry.registerConverter(new SingleValueConverterWrapper(converter), priority);
+ converterRegistry.registerConverter(
+ new SingleValueConverterWrapper(converter), priority);
}
}
/**
* Register a local {@link Converter} for a field.
- *
+ *
* @param definedIn the class type the field is defined in
* @param fieldName the field name
* @param converter the converter to use
* @since 1.3
*/
- public void registerLocalConverter(final Class> definedIn, final String fieldName, final Converter converter) {
+ public void registerLocalConverter(Class definedIn, String fieldName, Converter converter) {
if (localConversionMapper == null) {
- throw new InitializationException("No " + LocalConversionMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + LocalConversionMapper.class.getName()
+ + " available");
}
localConversionMapper.registerLocalConverter(definedIn, fieldName, converter);
}
/**
* Register a local {@link SingleValueConverter} for a field.
- *
+ *
* @param definedIn the class type the field is defined in
* @param fieldName the field name
* @param converter the converter to use
* @since 1.3
*/
- public void registerLocalConverter(final Class> definedIn, final String fieldName,
- final SingleValueConverter converter) {
- final Converter wrapper = new SingleValueConverterWrapper(converter);
- registerLocalConverter(definedIn, fieldName, wrapper);
+ public void registerLocalConverter(Class definedIn, String fieldName,
+ SingleValueConverter converter) {
+ registerLocalConverter(
+ definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter));
}
/**
- * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper MapperWrappers}.
+ * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper
+ * MapperWrappers}.
*
* @return the mapper
* @since 1.2
@@ -1411,7 +1795,7 @@
/**
* Retrieve the {@link ReflectionProvider} in use.
- *
+ *
* @return the mapper
* @since 1.2.1
*/
@@ -1424,18 +1808,17 @@
}
/**
- * Change mode for dealing with duplicate references. Valid values are XPATH_ABSOLUTE_REFERENCES,
- * XPATH_RELATIVE_REFERENCES, XStream.ID_REFERENCES and XStream.NO_REFERENCES
- * .
+ * Change mode for dealing with duplicate references. Valid values are
+ * XPATH_ABSOLUTE_REFERENCES, XPATH_RELATIVE_REFERENCES,
+ * XStream.ID_REFERENCES and XStream.NO_REFERENCES.
*
* @throws IllegalArgumentException if the mode is not one of the declared types
- * @see #setMarshallingStrategy(MarshallingStrategy)
* @see #XPATH_ABSOLUTE_REFERENCES
* @see #XPATH_RELATIVE_REFERENCES
* @see #ID_REFERENCES
* @see #NO_REFERENCES
*/
- public void setMode(final int mode) {
+ public void setMode(int mode) {
switch (mode) {
case NO_REFERENCES:
setMarshallingStrategy(new TreeMarshallingStrategy());
@@ -1444,17 +1827,21 @@
setMarshallingStrategy(new ReferenceByIdMarshallingStrategy());
break;
case XPATH_RELATIVE_REFERENCES:
- setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE));
+ setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
+ ReferenceByXPathMarshallingStrategy.RELATIVE));
break;
case XPATH_ABSOLUTE_REFERENCES:
- setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.ABSOLUTE));
+ setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
+ ReferenceByXPathMarshallingStrategy.ABSOLUTE));
break;
case SINGLE_NODE_XPATH_RELATIVE_REFERENCES:
- setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE
+ setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
+ ReferenceByXPathMarshallingStrategy.RELATIVE
| ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
break;
case SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES:
- setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.ABSOLUTE
+ setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
+ ReferenceByXPathMarshallingStrategy.ABSOLUTE
| ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
break;
default:
@@ -1464,246 +1851,280 @@
/**
* Adds a default implicit collection which is used for any unmapped XML tag.
- *
+ *
* @param ownerType class owning the implicit collection
- * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
- * the default implementation type of the collection type.
+ * @param fieldName name of the field in the ownerType. This field must be a concrete
+ * collection type or matching the default implementation type of the collection
+ * type.
*/
- public void addImplicitCollection(final Class> ownerType, final String fieldName) {
+ public void addImplicitCollection(Class ownerType, String fieldName) {
addImplicitCollection(ownerType, fieldName, null, null);
}
/**
* Adds implicit collection which is used for all items of the given itemType.
- *
+ *
* @param ownerType class owning the implicit collection
- * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
- * the default implementation type of the collection type.
+ * @param fieldName name of the field in the ownerType. This field must be a concrete
+ * collection type or matching the default implementation type of the collection
+ * type.
* @param itemType type of the items to be part of this collection
* @throws InitializationException if no {@link ImplicitCollectionMapper} is available
*/
- public void addImplicitCollection(final Class> ownerType, final String fieldName, final Class> itemType) {
+ public void addImplicitCollection(Class ownerType, String fieldName, Class itemType) {
addImplicitCollection(ownerType, fieldName, null, itemType);
}
/**
- * Adds implicit collection which is used for all items of the given element name defined by itemFieldName.
+ * Adds implicit collection which is used for all items of the given element name defined by
+ * itemFieldName.
*
* @param ownerType class owning the implicit collection
- * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching
- * the default implementation type of the collection type.
+ * @param fieldName name of the field in the ownerType. This field must be a concrete
+ * collection type or matching the default implementation type of the collection
+ * type.
* @param itemFieldName element name of the implicit collection
* @param itemType item type to be aliases be the itemFieldName
* @throws InitializationException if no {@link ImplicitCollectionMapper} is available
*/
- public void addImplicitCollection(final Class> ownerType, final String fieldName, final String itemFieldName,
- final Class> itemType) {
+ public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName,
+ Class itemType) {
addImplicitMap(ownerType, fieldName, itemFieldName, itemType, null);
}
/**
* Adds an implicit array.
- *
+ *
* @param ownerType class owning the implicit array
* @param fieldName name of the array field
- * @since 1.4
+ * @since 1.4
*/
- public void addImplicitArray(final Class> ownerType, final String fieldName) {
+ public void addImplicitArray(Class ownerType, String fieldName) {
addImplicitCollection(ownerType, fieldName);
}
/**
- * Adds an implicit array which is used for all items of the given itemType when the array type matches.
+ * Adds an implicit array which is used for all items of the given itemType when the array
+ * type matches.
*
* @param ownerType class owning the implicit array
* @param fieldName name of the array field in the ownerType
* @param itemType type of the items to be part of this array
- * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the array type does not
- * match the itemType
- * @since 1.4
+ * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the
+ * array type does not match the itemType
+ * @since 1.4
*/
- public void addImplicitArray(final Class> ownerType, final String fieldName, final Class> itemType) {
+ public void addImplicitArray(Class ownerType, String fieldName, Class itemType) {
addImplicitCollection(ownerType, fieldName, itemType);
}
/**
- * Adds an implicit array which is used for all items of the given element name defined by itemName.
+ * Adds an implicit array which is used for all items of the given element name defined by
+ * itemName.
*
* @param ownerType class owning the implicit array
* @param fieldName name of the array field in the ownerType
* @param itemName alias name of the items
* @throws InitializationException if no {@link ImplicitCollectionMapper} is available
- * @since 1.4
+ * @since 1.4
*/
- public void addImplicitArray(final Class> ownerType, final String fieldName, final String itemName) {
+ public void addImplicitArray(Class ownerType, String fieldName, String itemName) {
addImplicitCollection(ownerType, fieldName, itemName, null);
}
/**
* Adds an implicit map.
- *
+ *
* @param ownerType class owning the implicit map
- * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the
- * default implementation type of the map type.
+ * @param fieldName name of the field in the ownerType. This field must be a concrete
+ * map type or matching the default implementation type of the map
+ * type.
* @param itemType type of the items to be part of this map as value
* @param keyFieldName the name of the field of the itemType that is used for the key in the map
- * @since 1.4
+ * @since 1.4
*/
- public void addImplicitMap(final Class> ownerType, final String fieldName, final Class> itemType,
- final String keyFieldName) {
+ public void addImplicitMap(Class ownerType, String fieldName, Class itemType, String keyFieldName) {
addImplicitMap(ownerType, fieldName, null, itemType, keyFieldName);
}
/**
* Adds an implicit map.
- *
+ *
* @param ownerType class owning the implicit map
- * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the
- * default implementation type of the map type.
+ * @param fieldName name of the field in the ownerType. This field must be a concrete
+ * map type or matching the default implementation type of the map
+ * type.
* @param itemName alias name of the items
* @param itemType type of the items to be part of this map as value
* @param keyFieldName the name of the field of the itemType that is used for the key in the map
- * @since 1.4
+ * @since 1.4
*/
- public void addImplicitMap(final Class> ownerType, final String fieldName, final String itemName,
- final Class> itemType, final String keyFieldName) {
+ public void addImplicitMap(Class ownerType, String fieldName, String itemName,
+ Class itemType, String keyFieldName) {
if (implicitCollectionMapper == null) {
- throw new InitializationException("No " + ImplicitCollectionMapper.class.getName() + " available");
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ImplicitCollectionMapper.class.getName()
+ + " available");
}
implicitCollectionMapper.add(ownerType, fieldName, itemName, itemType, keyFieldName);
}
/**
* Create a DataHolder that can be used to pass data to the converters. The DataHolder is provided with a call to
- * {@link #marshal(Object, HierarchicalStreamWriter, DataHolder)} or
- * {@link #unmarshal(HierarchicalStreamReader, Object, DataHolder)}.
- *
+ * {@link #marshal(Object, HierarchicalStreamWriter, DataHolder)},
+ * {@link #unmarshal(HierarchicalStreamReader, Object, DataHolder)},
+ * {@link #createObjectInputStream(HierarchicalStreamReader, DataHolder)} or
+ * {@link #createObjectOutputStream(HierarchicalStreamWriter, String, DataHolder)}.
+ *
* @return a new {@link DataHolder}
*/
public DataHolder newDataHolder() {
return new MapBackedDataHolder();
}
/**
- * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
+ * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
+ * XStream.
*
* To change the name of the root element (from <object-stream>), use
* {@link #createObjectOutputStream(java.io.Writer, String)}.
*
*
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
* @since 1.0.3
*/
- public ObjectOutputStream createObjectOutputStream(final Writer writer) throws IOException {
- return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), "object-stream");
+ public ObjectOutputStream createObjectOutputStream(Writer writer) throws IOException {
+ return createObjectOutputStream(
+ hierarchicalStreamDriver.createWriter(writer), "object-stream");
}
/**
- * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
+ * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
+ * XStream.
*
* To change the name of the root element (from <object-stream>), use
* {@link #createObjectOutputStream(java.io.Writer, String)}.
*
*
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
* @since 1.0.3
*/
- public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer) throws IOException {
+ public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer)
+ throws IOException {
return createObjectOutputStream(writer, "object-stream");
}
/**
- * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
+ * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
+ * XStream.
*
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
* @since 1.0.3
*/
- public ObjectOutputStream createObjectOutputStream(final Writer writer, final String rootNodeName)
- throws IOException {
- return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName);
+ public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName)
+ throws IOException {
+ return createObjectOutputStream(
+ hierarchicalStreamDriver.createWriter(writer), rootNodeName);
}
/**
- * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.
+ * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
+ * using XStream.
*
* To change the name of the root element (from <object-stream>), use
* {@link #createObjectOutputStream(java.io.Writer, String)}.
*
*
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
* @since 1.3
*/
- public ObjectOutputStream createObjectOutputStream(final OutputStream out) throws IOException {
- return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), "object-stream");
+ public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException {
+ return createObjectOutputStream(
+ hierarchicalStreamDriver.createWriter(out), "object-stream");
}
/**
- * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.
+ * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
+ * using XStream.
*
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
* @since 1.3
*/
- public ObjectOutputStream createObjectOutputStream(final OutputStream out, final String rootNodeName)
- throws IOException {
- return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName);
+ public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName)
+ throws IOException {
+ return createObjectOutputStream(
+ hierarchicalStreamDriver.createWriter(out), rootNodeName);
}
/**
- * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
+ * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
+ * XStream.
*
- * Because an ObjectOutputStream can contain multiple items and XML only allows a single root node, the stream must
- * be written inside an enclosing node.
+ * Because an ObjectOutputStream can contain multiple items and XML only allows a single
+ * root node, the stream must be written inside an enclosing node.
*
*
- * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will be incomplete.
+ * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will
+ * be incomplete.
*
- *
+ *
* @param writer The writer to serialize the objects to.
* @param rootNodeName The name of the root node enclosing the stream of objects.
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
* @since 1.0.3
*/
- @SuppressWarnings("resource")
public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName)
throws IOException {
+ return createObjectOutputStream(writer, rootNodeName, null);
+ }
+
+ /**
+ * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
+ *
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
+ * @since 1.4.10
+ */
+ public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName,
+ final DataHolder dataHolder) throws IOException {
final StatefulWriter statefulWriter = new StatefulWriter(writer);
statefulWriter.startNode(rootNodeName, null);
return new CustomObjectOutputStream(new CustomObjectOutputStream.StreamCallback() {
- @Override
public void writeToStream(final Object object) {
- marshal(object, statefulWriter);
+ marshal(object, statefulWriter, dataHolder);
}
- @Override
- public void writeFieldsToStream(final Map fields) throws NotActiveException {
+ public void writeFieldsToStream(Map fields) throws NotActiveException {
throw new NotActiveException("not in call to writeObject");
}
- @Override
public void defaultWriteObject() throws NotActiveException {
throw new NotActiveException("not in call to writeObject");
}
- @Override
public void flush() {
statefulWriter.flush();
}
- @Override
public void close() {
if (statefulWriter.state() != StatefulWriter.STATE_CLOSED) {
statefulWriter.endNode();
@@ -1714,100 +2135,118 @@
}
/**
- * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
+ * Creates an ObjectInputStream that deserializes a stream of objects from a reader using
+ * XStream.
*
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @since 1.0.3
*/
- public ObjectInputStream createObjectInputStream(final Reader xmlReader) throws IOException {
+ public ObjectInputStream createObjectInputStream(Reader xmlReader) throws IOException {
return createObjectInputStream(hierarchicalStreamDriver.createReader(xmlReader));
}
/**
- * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream using XStream.
+ * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream
+ * using XStream.
*
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @since 1.3
*/
- public ObjectInputStream createObjectInputStream(final InputStream in) throws IOException {
+ public ObjectInputStream createObjectInputStream(InputStream in) throws IOException {
return createObjectInputStream(hierarchicalStreamDriver.createReader(in));
}
/**
- * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
Example
- *
+ * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
+ *
+ * It is necessary to call ObjectInputStream.close() when done, otherwise the stream might keep system resources.
+ *
+ *
Example
+ *
*
* ObjectInputStream in = xstream.createObjectOutputStream(aReader);
* int a = out.readInt();
* Object b = out.readObject();
* Object c = out.readObject();
*
*
- * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+ * String)
* @since 1.0.3
*/
public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader) throws IOException {
+ return createObjectInputStream(reader, null);
+ }
+
+ /**
+ * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
+ *
+ * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
+ * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
+ * @since 1.4.10
+ */
+ public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader, final DataHolder dataHolder)
+ throws IOException {
return new CustomObjectInputStream(new CustomObjectInputStream.StreamCallback() {
- @Override
public Object readFromStream() throws EOFException {
if (!reader.hasMoreChildren()) {
throw new EOFException();
}
reader.moveDown();
- final Object result = unmarshal(reader);
+ final Object result = unmarshal(reader, dataHolder);
reader.moveUp();
return result;
}
- @Override
- public Map readFieldsFromStream() throws IOException {
+ public Map readFieldsFromStream() throws IOException {
throw new NotActiveException("not in call to readObject");
}
- @Override
public void defaultReadObject() throws NotActiveException {
throw new NotActiveException("not in call to readObject");
}
- @Override
- public void registerValidation(final ObjectInputValidation validation, final int priority)
- throws NotActiveException {
+ public void registerValidation(ObjectInputValidation validation, int priority)
+ throws NotActiveException {
throw new NotActiveException("stream inactive");
}
- @Override
public void close() {
reader.close();
}
}, classLoaderReference);
}
/**
- * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will register for all kind
- * of classes and types of the current JDK, but not for any 3rd party type. To ensure that all other types are
- * loaded with your class loader, you should call this method as early as possible - or consider to provide the
- * class loader directly in the constructor.
+ * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will
+ * register for all kind of classes and types of the current JDK, but not for any 3rd party
+ * type. To ensure that all other types are loaded with your class loader, you should call
+ * this method as early as possible - or consider to provide the class loader directly in
+ * the constructor.
*
* @since 1.1.1
*/
- public void setClassLoader(final ClassLoader classLoader) {
+ public void setClassLoader(ClassLoader classLoader) {
classLoaderReference.setReference(classLoader);
}
/**
* Retrieve the ClassLoader XStream uses to load classes.
- *
+ *
* @since 1.1.1
*/
public ClassLoader getClassLoader() {
return classLoaderReference.getReference();
}
-
+
/**
- * Retrieve the reference to this instance' ClassLoader. Use this reference for other XStream components (like
- * converters) to ensure that they will use a changed ClassLoader instance automatically.
+ * Retrieve the reference to this instance' ClassLoader. Use this reference for other
+ * XStream components (like converters) to ensure that they will use a changed ClassLoader
+ * instance automatically.
*
* @return the reference
* @since 1.4.5
@@ -1817,22 +2256,24 @@
}
/**
- * Prevents a field from being serialized. To omit a field you must always provide the declaring type and not
- * necessarily the type that is converted.
+ * Prevents a field from being serialized. To omit a field you must always provide the
+ * declaring type and not necessarily the type that is converted.
*
* @since 1.1.3
- * @throws InitializationException if no {@link FieldAliasingMapper} is available
+ * @throws InitializationException if no {@link ElementIgnoringMapper} is available
*/
- public void omitField(final Class> definedIn, final String fieldName) {
- if (fieldAliasingMapper == null) {
- throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available");
+ public void omitField(Class definedIn, String fieldName) {
+ if (elementIgnoringMapper == null) {
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ElementIgnoringMapper.class.getName()
+ + " available");
}
- fieldAliasingMapper.omitField(definedIn, fieldName);
+ elementIgnoringMapper.omitField(definedIn, fieldName);
}
-
+
/**
* Ignore all unknown elements.
- *
+ *
* @since 1.4.5
*/
public void ignoreUnknownElements() {
@@ -1841,217 +2282,276 @@
/**
* Add pattern for unknown element names to ignore.
- *
+ *
* @param pattern the name pattern as regular expression
* @since 1.4.5
*/
- public void ignoreUnknownElements(final String pattern) {
+ public void ignoreUnknownElements(String pattern) {
ignoreUnknownElements(Pattern.compile(pattern));
}
/**
* Add pattern for unknown element names to ignore.
- *
+ *
* @param pattern the name pattern as regular expression
* @since 1.4.5
*/
- private void ignoreUnknownElements(final Pattern pattern) {
- if (fieldAliasingMapper == null) {
- throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available");
+ public void ignoreUnknownElements(final Pattern pattern) {
+ if (elementIgnoringMapper == null) {
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ElementIgnoringMapper.class.getName()
+ + " available");
}
- fieldAliasingMapper.addFieldsToIgnore(pattern);
+ elementIgnoringMapper.addElementsToIgnore(pattern);
}
/**
* Process the annotations of the given types and configure the XStream.
- *
+ *
* @param types the types with XStream annotations
* @since 1.3
*/
- public void processAnnotations(final Class>... types) {
- if (annotationMapper == null) {
- throw new InitializationException("No " + AnnotationMapper.class.getName() + " available");
+ public void processAnnotations(final Class[] types) {
+ if (annotationConfiguration == null) {
+ throw new com.thoughtworks.xstream.InitializationException("No "
+ + ANNOTATION_MAPPER_TYPE
+ + " available");
}
- annotationMapper.processAnnotations(types);
+ annotationConfiguration.processAnnotations(types);
}
/**
- * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies that the XStream is
- * configured while it is processing the XML steams. This is a potential concurrency problem. Also is it technically
- * not possible to detect all class aliases at deserialization. You have been warned!
+ * Process the annotations of the given type and configure the XStream. A call of this
+ * method will automatically turn the auto-detection mode for annotations off.
*
+ * @param type the type with XStream annotations
+ * @since 1.3
+ */
+ public void processAnnotations(final Class type) {
+ processAnnotations(new Class[]{type});
+ }
+
+ /**
+ * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies
+ * that the XStream is configured while it is processing the XML steams. This is a potential
+ * concurrency problem. Also is it technically not possible to detect all class aliases at
+ * deserialization. You have been warned!
+ *
* @param mode true if annotations are auto-detected
* @since 1.3
*/
- public void autodetectAnnotations(final boolean mode) {
- if (annotationMapper != null) {
- annotationMapper.autodetectAnnotations(mode);
+ public void autodetectAnnotations(boolean mode) {
+ if (annotationConfiguration != null) {
+ annotationConfiguration.autodetectAnnotations(mode);
}
}
-
+
/**
* Add a new security permission.
+ *
*
* Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or
* {@link AnyTypePermission} will implicitly wipe any existing permission.
*
- *
+ *
* @param permission the permission to add
* @since 1.4.7
*/
- public void addPermission(final TypePermission permission) {
+ public void addPermission(TypePermission permission) {
if (securityMapper != null) {
+ insecureWarning &= permission != NoTypePermission.NONE;
securityMapper.addPermission(permission);
}
}
-
+
/**
* Add security permission for explicit types by name.
- *
+ *
* @param names the type names to allow
* @since 1.4.7
*/
- public void allowTypes(final String... names) {
+ public void allowTypes(String[] names) {
addPermission(new ExplicitTypePermission(names));
}
-
+
/**
* Add security permission for explicit types.
- *
+ *
* @param types the types to allow
* @since 1.4.7
*/
- public void allowTypes(final Class>... types) {
+ public void allowTypes(Class[] types) {
addPermission(new ExplicitTypePermission(types));
}
-
+
/**
* Add security permission for a type hierarchy.
- *
+ *
* @param type the base type to allow
* @since 1.4.7
*/
- public void allowTypeHierarchy(final Class> type) {
+ public void allowTypeHierarchy(Class type) {
addPermission(new TypeHierarchyPermission(type));
}
-
+
/**
* Add security permission for types matching one of the specified regular expressions.
- *
+ *
* @param regexps the regular expressions to allow type names
* @since 1.4.7
*/
- public void allowTypesByRegExp(final String... regexps) {
+ public void allowTypesByRegExp(String[] regexps) {
addPermission(new RegExpTypePermission(regexps));
}
-
+
/**
* Add security permission for types matching one of the specified regular expressions.
- *
+ *
* @param regexps the regular expressions to allow type names
* @since 1.4.7
*/
- public void allowTypesByRegExp(final Pattern... regexps) {
+ public void allowTypesByRegExp(Pattern[] regexps) {
addPermission(new RegExpTypePermission(regexps));
}
-
+
/**
* Add security permission for types matching one of the specified wildcard patterns.
*
* Supported are patterns with path expressions using dot as separator:
*
*
*
?: one non-control character except separator, e.g. for 'java.net.Inet?Address'
- *
*: arbitrary number of non-control characters except separator, e.g. for types in a package like
- * 'java.lang.*'
- *
**: arbitrary number of non-control characters including separator, e.g. for types in a package and
- * subpackages like 'java.lang.**'
+ *
*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'
+ *
**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'
*
- *
+ *
* @param patterns the patterns to allow type names
* @since 1.4.7
*/
- public void allowTypesByWildcard(final String... patterns) {
+ public void allowTypesByWildcard(String[] patterns) {
addPermission(new WildcardTypePermission(patterns));
}
-
+
/**
* Add security permission denying another one.
- *
+ *
* @param permission the permission to deny
* @since 1.4.7
*/
- public void denyPermission(final TypePermission permission) {
+ public void denyPermission(TypePermission permission) {
addPermission(new NoPermission(permission));
}
-
+
/**
* Add security permission forbidding explicit types by name.
- *
+ *
* @param names the type names to forbid
* @since 1.4.7
*/
- public void denyTypes(final String... names) {
+ public void denyTypes(String[] names) {
denyPermission(new ExplicitTypePermission(names));
}
-
+
/**
* Add security permission forbidding explicit types.
- *
+ *
* @param types the types to forbid
* @since 1.4.7
*/
- public void denyTypes(final Class>... types) {
+ public void denyTypes(Class[] types) {
denyPermission(new ExplicitTypePermission(types));
}
-
+
/**
* Add security permission forbidding a type hierarchy.
- *
+ *
* @param type the base type to forbid
* @since 1.4.7
*/
- public void denyTypeHierarchy(final Class> type) {
+ public void denyTypeHierarchy(Class type) {
denyPermission(new TypeHierarchyPermission(type));
}
-
+
/**
* Add security permission forbidding types matching one of the specified regular expressions.
- *
+ *
* @param regexps the regular expressions to forbid type names
* @since 1.4.7
*/
- public void denyTypesByRegExp(final String... regexps) {
+ public void denyTypesByRegExp(String[] regexps) {
denyPermission(new RegExpTypePermission(regexps));
}
-
+
/**
* Add security permission forbidding types matching one of the specified regular expressions.
- *
+ *
* @param regexps the regular expressions to forbid type names
* @since 1.4.7
*/
- public void denyTypesByRegExp(final Pattern... regexps) {
+ public void denyTypesByRegExp(Pattern[] regexps) {
denyPermission(new RegExpTypePermission(regexps));
}
-
+
/**
* Add security permission forbidding types matching one of the specified wildcard patterns.
*
* Supported are patterns with path expressions using dot as separator:
*
*
*
?: one non-control character except separator, e.g. for 'java.net.Inet?Address'
- *
*: arbitrary number of non-control characters except separator, e.g. for types in a package like
- * 'java.lang.*'
- *
**: arbitrary number of non-control characters including separator, e.g. for types in a package and
- * subpackages like 'java.lang.**'
+ *
*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'
+ *
**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'
*
- *
+ *
* @param patterns the patterns to forbid names
* @since 1.4.7
*/
- public void denyTypesByWildcard(final String... patterns) {
+ public void denyTypesByWildcard(String[] patterns) {
denyPermission(new WildcardTypePermission(patterns));
}
+
+ /**
+ * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException}
+ * instead
+ */
+ public static class InitializationException extends XStreamException {
+ /**
+ * @deprecated As of 1.3, use
+ * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String, Throwable)}
+ * instead
+ */
+ public InitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @deprecated As of 1.3, use
+ * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)}
+ * instead
+ */
+ public InitializationException(String message) {
+ super(message);
+ }
+ }
+
+ private class InternalBlackList implements Converter {
+
+ public boolean canConvert(final Class type) {
+ return (type == void.class || type == Void.class)
+ || (insecureWarning
+ && type != null
+ && (type.getName().equals("java.beans.EventHandler")
+ || type.getName().endsWith("$LazyIterator")
+ || type.getName().startsWith("javax.crypto.")));
+ }
+
+ public void marshal(final Object source, final HierarchicalStreamWriter writer,
+ final MarshallingContext context) {
+ throw new ConversionException("Security alert. Marshalling rejected.");
+ }
+
+ public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
+ throw new ConversionException("Security alert. Unmarshalling rejected.");
+ }
+ }
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamException.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamException.java (.../XStreamException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamException.java (.../XStreamException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2013 XStream Committers.
+ * Copyright (C) 2007, 2008, 2016 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -10,15 +10,17 @@
*/
package com.thoughtworks.xstream;
+import com.thoughtworks.xstream.core.BaseException;
+
/**
* Base exception for all thrown exceptions with XStream.
*
* @author Joe Walnes
* @author Jörg Schaible
* @since 1.3
*/
-public class XStreamException extends RuntimeException {
+public class XStreamException extends BaseException {
/**
* Default constructor.
@@ -58,6 +60,6 @@
* @since 1.3
*/
public XStreamException(String message, Throwable cause) {
- super(message + (cause == null ? "" : " : " + cause.getMessage()), cause);
+ super(message, cause);
}
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamer.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamer.java (.../XStreamer.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamer.java (.../XStreamer.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007, 2014, 2016, 2017 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -21,7 +21,6 @@
import javax.xml.datatype.DatatypeFactory;
-import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.ConverterLookup;
import com.thoughtworks.xstream.converters.ConverterMatcher;
import com.thoughtworks.xstream.converters.ConverterRegistry;
@@ -33,34 +32,41 @@
import com.thoughtworks.xstream.core.JVM;
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.naming.NameCoder;
import com.thoughtworks.xstream.io.xml.XppDriver;
import com.thoughtworks.xstream.mapper.Mapper;
+import com.thoughtworks.xstream.security.AnyTypePermission;
import com.thoughtworks.xstream.security.TypeHierarchyPermission;
import com.thoughtworks.xstream.security.TypePermission;
import com.thoughtworks.xstream.security.WildcardTypePermission;
-
/**
- * Self-contained XStream generator. The class is a utility to write XML streams that contain additionally the XStream
- * that was used to serialize the object graph. Such a stream can be unmarshalled using this embedded XStream instance,
- * that kept any settings.
+ * Self-contained XStream generator. The class is a utility to write XML streams that contain
+ * additionally the XStream that was used to serialize the object graph. Such a stream can
+ * be unmarshalled using this embedded XStream instance, that kept any settings.
*
* @author Jörg Schaible
* @since 1.2
*/
public class XStreamer {
private final static TypePermission[] PERMISSIONS = {
- new TypeHierarchyPermission(ConverterMatcher.class), new TypeHierarchyPermission(Mapper.class),
- new TypeHierarchyPermission(XStream.class), new TypeHierarchyPermission(ReflectionProvider.class),
- new TypeHierarchyPermission(JavaBeanProvider.class), new TypeHierarchyPermission(FieldKeySorter.class),
- new TypeHierarchyPermission(ConverterLookup.class), new TypeHierarchyPermission(ConverterRegistry.class),
+ new TypeHierarchyPermission(ConverterMatcher.class),
+ new TypeHierarchyPermission(Mapper.class),
+ new TypeHierarchyPermission(XStream.class),
+ new TypeHierarchyPermission(ReflectionProvider.class),
+ new TypeHierarchyPermission(JavaBeanProvider.class),
+ new TypeHierarchyPermission(FieldKeySorter.class),
+ new TypeHierarchyPermission(ConverterLookup.class),
+ new TypeHierarchyPermission(ConverterRegistry.class),
new TypeHierarchyPermission(HierarchicalStreamDriver.class),
- new TypeHierarchyPermission(MarshallingStrategy.class), new TypeHierarchyPermission(MarshallingContext.class),
- new TypeHierarchyPermission(UnmarshallingContext.class), new TypeHierarchyPermission(NameCoder.class),
+ new TypeHierarchyPermission(MarshallingStrategy.class),
+ new TypeHierarchyPermission(MarshallingContext.class),
+ new TypeHierarchyPermission(UnmarshallingContext.class),
+ new TypeHierarchyPermission(NameCoder.class),
new TypeHierarchyPermission(TypePermission.class),
- new WildcardTypePermission(JVM.class.getPackage().getName() + ".**"),
+ new WildcardTypePermission(new String[]{JVM.class.getPackage().getName()+".**"}),
new TypeHierarchyPermission(DatatypeFactory.class) // required by DurationConverter
};
@@ -79,27 +85,30 @@
} catch (final ObjectStreamException e) {
throw e;
} catch (final IOException e) {
- throw new ConversionException("Unexpected IO error from a StringWriter", e);
+ throw new StreamException("Unexpected IO error from a StringWriter", e);
}
return writer.toString();
}
/**
* Serialize an object including the XStream to the given Writer as pretty-printed XML.
*
- * Warning: XStream will serialize itself into this XML stream. To read such an XML code, you should use
- * {@link XStreamer#fromXML(Reader)} or one of the other overloaded methods. Since a lot of internals are written
- * into the stream, you cannot expect to use such an XML to work with another XStream version or with XStream
- * running on different JDKs and/or versions. We have currently no JDK 1.3 support, nor will the
- * PureReflectionConverter work with a JDK less than 1.5.
+ * Warning: XStream will serialize itself into this XML stream. To read such an XML code, you
+ * should use {@link XStreamer#fromXML(Reader)} or one of the other overloaded
+ * methods. Since a lot of internals are written into the stream, you cannot expect to use such
+ * an XML to work with another XStream version or with XStream running on different JDKs and/or
+ * versions. We have currently no JDK 1.3 support, nor will the PureReflectionConverter work
+ * with a JDK less than 1.5.
*
*
* @throws IOException if an error occurs reading from the Writer.
* @throws com.thoughtworks.xstream.XStreamException if the object cannot be serialized
* @since 1.2
*/
- public void toXML(final XStream xstream, final Object obj, final Writer out) throws IOException {
+ public void toXML(final XStream xstream, final Object obj, final Writer out)
+ throws IOException {
final XStream outer = new XStream();
+ XStream.setupDefaultSecurity(outer);
final ObjectOutputStream oos = outer.createObjectOutputStream(out);
try {
oos.writeObject(xstream);
@@ -111,8 +120,8 @@
}
/**
- * Deserialize a self-contained XStream with object from a String. The method will use internally an XppDriver to
- * load the contained XStream instance with default permissions.
+ * Deserialize a self-contained XStream with object from a String. The method will use
+ * internally an XppDriver to load the contained XStream instance with default permissions.
*
* @param xml the XML data
* @throws ClassNotFoundException if a class in the XML stream cannot be found
@@ -121,19 +130,19 @@
* @since 1.2
* @see #toXML(XStream, Object, Writer)
*/
- public T fromXML(final String xml) throws ClassNotFoundException, ObjectStreamException {
+ public Object fromXML(final String xml) throws ClassNotFoundException, ObjectStreamException {
try {
return fromXML(new StringReader(xml));
} catch (final ObjectStreamException e) {
throw e;
} catch (final IOException e) {
- throw new ConversionException("Unexpected IO error from a StringReader", e);
+ throw new StreamException("Unexpected IO error from a StringReader", e);
}
}
/**
- * Deserialize a self-contained XStream with object from a String. The method will use internally an XppDriver to
- * load the contained XStream instance.
+ * Deserialize a self-contained XStream with object from a String. The method will use
+ * internally an XppDriver to load the contained XStream instance.
*
* @param xml the XML data
* @param permissions the permissions to use (ensure that they include the defaults)
@@ -143,14 +152,13 @@
* @since 1.4.7
* @see #toXML(XStream, Object, Writer)
*/
- public T fromXML(final String xml, final TypePermission... permissions)
- throws ClassNotFoundException, ObjectStreamException {
+ public Object fromXML(final String xml, final TypePermission[] permissions) throws ClassNotFoundException, ObjectStreamException {
try {
return fromXML(new StringReader(xml), permissions);
} catch (final ObjectStreamException e) {
throw e;
} catch (final IOException e) {
- throw new ConversionException("Unexpected IO error from a StringReader", e);
+ throw new StreamException("Unexpected IO error from a StringReader", e);
}
}
@@ -165,14 +173,14 @@
* @since 1.2
* @see #toXML(XStream, Object, Writer)
*/
- public T fromXML(final HierarchicalStreamDriver driver, final String xml)
+ public Object fromXML(final HierarchicalStreamDriver driver, final String xml)
throws ClassNotFoundException, ObjectStreamException {
try {
return fromXML(driver, new StringReader(xml));
} catch (final ObjectStreamException e) {
throw e;
} catch (final IOException e) {
- throw new ConversionException("Unexpected IO error from a StringReader", e);
+ throw new StreamException("Unexpected IO error from a StringReader", e);
}
}
@@ -188,20 +196,20 @@
* @since 1.4.7
* @see #toXML(XStream, Object, Writer)
*/
- public T fromXML(final HierarchicalStreamDriver driver, final String xml, final TypePermission... permissions)
+ public Object fromXML(final HierarchicalStreamDriver driver, final String xml, final TypePermission[] permissions)
throws ClassNotFoundException, ObjectStreamException {
try {
return fromXML(driver, new StringReader(xml), permissions);
} catch (final ObjectStreamException e) {
throw e;
} catch (final IOException e) {
- throw new ConversionException("Unexpected IO error from a StringReader", e);
+ throw new StreamException("Unexpected IO error from a StringReader", e);
}
}
/**
- * Deserialize a self-contained XStream with object from an XML Reader. The method will use internally an XppDriver
- * to load the contained XStream instance with default permissions.
+ * Deserialize a self-contained XStream with object from an XML Reader. The method will use
+ * internally an XppDriver to load the contained XStream instance with default permissions.
*
* @param xml the {@link Reader} providing the XML data
* @throws IOException if an error occurs reading from the Reader.
@@ -210,13 +218,14 @@
* @since 1.2
* @see #toXML(XStream, Object, Writer)
*/
- public T fromXML(final Reader xml) throws IOException, ClassNotFoundException {
+ public Object fromXML(final Reader xml)
+ throws IOException, ClassNotFoundException {
return fromXML(new XppDriver(), xml);
}
/**
- * Deserialize a self-contained XStream with object from an XML Reader. The method will use internally an XppDriver
- * to load the contained XStream instance.
+ * Deserialize a self-contained XStream with object from an XML Reader. The method will use
+ * internally an XppDriver to load the contained XStream instance.
*
* @param xml the {@link Reader} providing the XML data
* @param permissions the permissions to use (ensure that they include the defaults)
@@ -226,24 +235,24 @@
* @since 1.4.7
* @see #toXML(XStream, Object, Writer)
*/
- public T fromXML(final Reader xml, final TypePermission... permissions)
+ public Object fromXML(final Reader xml, final TypePermission[] permissions)
throws IOException, ClassNotFoundException {
return fromXML(new XppDriver(), xml, permissions);
}
/**
* Deserialize a self-contained XStream with object from an XML Reader.
- *
+ *
* @param driver the implementation to use
* @param xml the {@link Reader} providing the XML data
* @throws IOException if an error occurs reading from the Reader.
* @throws ClassNotFoundException if a class in the XML stream cannot be found
* @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
* @since 1.2
*/
- public T fromXML(final HierarchicalStreamDriver driver, final Reader xml)
+ public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml)
throws IOException, ClassNotFoundException {
- return fromXML(driver, xml, PERMISSIONS);
+ return fromXML(driver, xml, new TypePermission[]{AnyTypePermission.ANY});
}
/**
@@ -257,21 +266,20 @@
* @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
* @since 1.4.7
*/
- public T fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission... permissions)
+ public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission[] permissions)
throws IOException, ClassNotFoundException {
final XStream outer = new XStream(driver);
- for (final TypePermission permission : permissions) {
- outer.addPermission(permission);
+ XStream.setupDefaultSecurity(outer);
+ for(int i = 0; i < permissions.length; ++i) {
+ outer.addPermission(permissions[i]);
}
final HierarchicalStreamReader reader = driver.createReader(xml);
final ObjectInputStream configIn = outer.createObjectInputStream(reader);
try {
final XStream configured = (XStream)configIn.readObject();
final ObjectInputStream in = configured.createObjectInputStream(reader);
try {
- @SuppressWarnings("unchecked")
- final T t = (T)in.readObject();
- return t;
+ return in.readObject();
} finally {
in.close();
}
@@ -290,6 +298,6 @@
* @since 1.4.7
*/
public static TypePermission[] getDefaultPermissions() {
- return PERMISSIONS.clone();
+ return (TypePermission[])PERMISSIONS.clone();
}
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationProvider.java
===================================================================
diff -u
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationProvider.java (revision 0)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationProvider.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 02. March 2006 by Mauro Talevi
+ */
+package com.thoughtworks.xstream.annotations;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+
+/**
+ * An utility class to provide annotations from different sources
+ *
+ * @author Guilherme Silveira
+ * @deprecated As of 1.3
+ */
+@Deprecated
+public class AnnotationProvider {
+
+ /**
+ * Returns a field annotation based on an annotation type
+ *
+ * @param field the annotation Field
+ * @param annotationClass the annotation Class
+ * @return The Annotation type
+ * @deprecated As of 1.3
+ */
+ @Deprecated
+ public T getAnnotation(Field field, Class annotationClass) {
+ return field.getAnnotation(annotationClass);
+ }
+
+}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.java
===================================================================
diff -u
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.java (revision 0)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 02. March 2006 by Mauro Talevi
+ */
+package com.thoughtworks.xstream.annotations;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.ConverterMatcher;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.SingleValueConverter;
+import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
+import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
+import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+
+/**
+ * ReflectionConverter which uses an AnnotationProvider to marshall and unmarshall fields based
+ * on the annotated converters.
+ *
+ * @author Guilherme Silveira
+ * @author Mauro Talevi
+ * @deprecated As of 1.3, build into {@link ReflectionConverter}
+ */
+@Deprecated
+public class AnnotationReflectionConverter extends ReflectionConverter {
+
+ private final AnnotationProvider annotationProvider;
+
+ private final Map, Converter> cachedConverters;
+
+ @Deprecated
+ public AnnotationReflectionConverter(
+ Mapper mapper, ReflectionProvider reflectionProvider,
+ AnnotationProvider annotationProvider) {
+ super(mapper, reflectionProvider);
+ this.annotationProvider = annotationProvider;
+ this.cachedConverters = new HashMap, Converter>();
+ }
+
+ protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
+ XStreamConverter annotation = annotationProvider.getAnnotation(
+ field, XStreamConverter.class);
+ if (annotation != null) {
+ Class extends ConverterMatcher> type = annotation.value();
+ ensureCache(type);
+ context.convertAnother(newObj, cachedConverters.get(type));
+ } else {
+ context.convertAnother(newObj);
+ }
+ }
+
+ private void ensureCache(Class extends ConverterMatcher> type) {
+ if (!this.cachedConverters.containsKey(type)) {
+ cachedConverters.put(type, newInstance(type));
+ }
+ }
+
+ protected Object unmarshallField(
+ final UnmarshallingContext context, final Object result,
+ Class type, Field field) {
+ XStreamConverter annotation = annotationProvider.getAnnotation(
+ field, XStreamConverter.class);
+ if (annotation != null) {
+ Class extends Converter> converterType = (Class extends Converter>)annotation.value();
+ ensureCache(converterType);
+ return context.convertAnother(result, type, cachedConverters.get(converterType));
+ } else {
+ return context.convertAnother(result, type);
+ }
+ }
+
+ /**
+ * Instantiates a converter using its default constructor.
+ *
+ * @param type the converter type to instantiate
+ * @return the new instance
+ */
+ private Converter newInstance(Class extends ConverterMatcher> type) {
+ Converter converter;
+ // TODO: We need a separate exception for runtime initialization.
+ try {
+ if (SingleValueConverter.class.isAssignableFrom(type)) {
+ final SingleValueConverter svc = (SingleValueConverter)type.getConstructor().newInstance();
+ converter = new SingleValueConverterWrapper(svc);
+ } else {
+ converter = (Converter)type.getConstructor().newInstance();
+ }
+ } catch (InvocationTargetException e) {
+ throw new ObjectAccessException("Cannot construct " + type.getName(), e
+ .getCause());
+ } catch (InstantiationException e) {
+ throw new ObjectAccessException("Cannot construct " + type.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new ObjectAccessException("Cannot construct " + type.getName(), e);
+ } catch (NoSuchMethodException e) {
+ throw new ObjectAccessException("Cannot construct " + type.getName(), e);
+ }
+ return converter;
+ }
+
+}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/Annotations.java
===================================================================
diff -u
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/Annotations.java (revision 0)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/Annotations.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2005 Joe Walnes.
+ * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 11. August 2005 by Mauro Talevi
+ */
+package com.thoughtworks.xstream.annotations;
+
+import com.thoughtworks.xstream.XStream;
+
+
+/**
+ * Contains utility methods that enable to configure an XStream instance with class and field
+ * aliases, based on a class decorated with annotations defined in this package.
+ *
+ * @author Emil Kirschner
+ * @author Chung-Onn Cheong
+ * @author Guilherme Silveira
+ * @author Jörg Schaible
+ * @deprecated As of 1.3, use {@link XStream#processAnnotations(Class[])}
+ */
+@Deprecated
+public class Annotations {
+ /**
+ * This class is not instantiable
+ */
+ private Annotations() {
+ }
+
+ /**
+ * Configures aliases on the specified XStream object based on annotations that decorate the
+ * specified class. It will recursively invoke itself. If a field is parameterized, a
+ * recursive call for each of its parameters type will be made.
+ *
+ * @param topLevelClasses the class for which the XStream object is configured. This class
+ * is expected to be decorated with annotations defined in this package.
+ * @param xstream the XStream object that will be configured
+ * @deprecated As of 1.3, use {@link XStream#processAnnotations(Class[])}
+ */
+ @Deprecated
+ public static synchronized void configureAliases(XStream xstream,
+ Class> ... topLevelClasses) {
+ xstream.processAnnotations(topLevelClasses);
+ }
+}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamContainedType.java
===================================================================
diff -u
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamContainedType.java (revision 0)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamContainedType.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2005 Joe Walnes.
+ * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 11. August 2005 by Mauro Talevi
+ */
+package com.thoughtworks.xstream.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to notify Annotations.configureAliases that it should recursively invoke itself for
+ * all parameterized types of this field.
+ *
+ * @author Emil Kirschner
+ * @author Chung-Onn Cheong
+ * @deprecated As of 1.3, recursive behaviour is now always used and the annotation is therefore superfluous
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Deprecated
+public @interface XStreamContainedType {
+
+}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamConverter.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamConverter.java (.../XStreamConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamConverter.java (.../XStreamConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Joe Walnes.
- * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2016 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -106,4 +106,12 @@
double[] doubles() default {};
boolean[] booleans() default {};
+
+ /**
+ * Provide null types as arguments for the converter's constructor arguments.
+ *
+ * @return the types provided as null values
+ * @since 1.4.9
+ */
+ Class>[] nulls() default {};
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamImplicitCollection.java
===================================================================
diff -u
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamImplicitCollection.java (revision 0)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamImplicitCollection.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2005 Joe Walnes.
+ * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 16. September 2005 by Mauro Talevi
+ */
+package com.thoughtworks.xstream.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *
+ * @author Chung-Onn Cheong
+ * @deprecated As of 1.3, use @XStreamImplicit at field level
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface XStreamImplicitCollection {
+ String value(); //fieldName
+ String item() default ""; //itemfieldName
+}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConversionException.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConversionException.java (.../ConversionException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConversionException.java (.../ConversionException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003, 2004, 2005 Joe Walnes.
- * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -11,106 +11,29 @@
*/
package com.thoughtworks.xstream.converters;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import com.thoughtworks.xstream.XStreamException;
-
-
/**
- * Thrown by {@link Converter} implementations when they cannot convert an object to/from textual data. When this
- * exception is thrown it can be passed around to things that accept an {@link ErrorWriter}, allowing them to add
- * diagnostics to the stack trace.
- *
+ * Thrown by {@link Converter} implementations when they cannot convert an object
+ * to/from textual data.
+ *
+ * When this exception is thrown it can be passed around to things that accept an
+ * {@link ErrorWriter}, allowing them to add diagnostics to the stack trace.
+ *
* @author Joe Walnes
* @author Jörg Schaible
+ *
* @see ErrorWriter
*/
-public class ConversionException extends XStreamException implements ErrorWriter {
+public class ConversionException extends ErrorWritingException {
- private static final String SEPARATOR = "\n-------------------------------";
- private final Map stuff = new LinkedHashMap();
-
- public ConversionException(final String msg, final Throwable cause) {
+ public ConversionException(String msg, Throwable cause) {
super(msg, cause);
- if (msg != null) {
- add("message", msg);
- }
- if (cause != null) {
- add("cause-exception", cause.getClass().getName());
- add("cause-message", cause instanceof ConversionException
- ? ((ConversionException)cause).getShortMessage()
- : cause.getMessage());
- }
}
- public ConversionException(final String msg) {
+ public ConversionException(String msg) {
super(msg);
}
- public ConversionException(final Throwable cause) {
- this(cause.getMessage(), cause);
+ public ConversionException(Throwable cause) {
+ super(cause);
}
-
- @Override
- public String get(final String errorKey) {
- return stuff.get(errorKey);
- }
-
- @Override
- public void add(final String name, final String information) {
- String key = name;
- int i = 0;
- while (stuff.containsKey(key)) {
- final String value = stuff.get(key);
- if (information.equals(value)) {
- return;
- }
- key = name + "[" + ++i + "]";
- }
- stuff.put(key, information);
- }
-
- @Override
- public void set(final String name, final String information) {
- String key = name;
- int i = 0;
- stuff.put(key, information); // keep order
- while (stuff.containsKey(key)) {
- if (i != 0) {
- stuff.remove(key);
- }
- key = name + "[" + ++i + "]";
- }
- }
-
- @Override
- public Iterator keys() {
- return stuff.keySet().iterator();
- }
-
- @Override
- public String getMessage() {
- final StringBuilder result = new StringBuilder();
- if (super.getMessage() != null) {
- result.append(super.getMessage());
- }
- if (!result.toString().endsWith(SEPARATOR)) {
- result.append("\n---- Debugging information ----");
- }
- for (final Iterator iterator = keys(); iterator.hasNext();) {
- final String k = iterator.next();
- final String v = get(k);
- result.append('\n').append(k);
- result.append(" ".substring(Math.min(20, k.length())));
- result.append(": ").append(v);
- }
- result.append(SEPARATOR);
- return result.toString();
- }
-
- public String getShortMessage() {
- return super.getMessage();
- }
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/Converter.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/Converter.java (.../Converter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/Converter.java (.../Converter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003, 2004 Joe Walnes.
- * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007, 2013 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -14,30 +14,29 @@
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
-
/**
- * Converter implementations are responsible marshalling Java objects to/from textual data.
- *
- * If an exception occurs during processing, a {@link ConversionException} should be thrown.
- *
- *
- * If working with the high level {@link com.thoughtworks.xstream.XStream} facade, you can register new converters using
- * the XStream.registerConverter() method.
- *
- *
- * If working with the lower level API, the {@link com.thoughtworks.xstream.converters.ConverterLookup} implementation
- * is responsible for looking up the appropriate converter.
- *
- *
- * Converters for object that can store all information in a single value should implement
- * {@link com.thoughtworks.xstream.converters.SingleValueConverter}.
- * {@link com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter} provides a starting point.
- *
- *
- * {@link com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter} provides a starting point for
- * objects that hold a collection of other objects (such as Lists and Maps).
- *
If an exception occurs during processing, a {@link ConversionException}
+ * should be thrown.
+ *
+ *
If working with the high level {@link com.thoughtworks.xstream.XStream} facade,
+ * you can register new converters using the XStream.registerConverter() method.
+ *
+ *
If working with the lower level API, the
+ * {@link com.thoughtworks.xstream.converters.ConverterLookup} implementation is
+ * responsible for looking up the appropriate converter.
+ *
+ *
Converters for object that can store all information in a single value
+ * should implement {@link com.thoughtworks.xstream.converters.SingleValueConverter}.
+ * {@link com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter}
+ * provides a starting point.
+ *
+ *
{@link com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter}
+ * provides a starting point for objects that hold a collection of other objects
+ * (such as Lists and Maps).
+ *
* @author Joe Walnes
* @see com.thoughtworks.xstream.XStream
* @see com.thoughtworks.xstream.converters.ConverterLookup
@@ -48,19 +47,19 @@
/**
* Convert an object to textual data.
- *
- * @param source the object to be marshalled.
- * @param writer a stream to write to.
- * @param context a context that allows nested objects to be processed by XStream.
+ *
+ * @param source The object to be marshalled.
+ * @param writer A stream to write to.
+ * @param context A context that allows nested objects to be processed by XStream.
*/
void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context);
/**
* Convert textual data back into an object.
- *
- * @param reader the stream to read the text from.
- * @param context a context that allows nested objects to be processed by XStream.
- * @return the resulting object.
+ *
+ * @param reader The stream to read the text from.
+ * @param context
+ * @return The resulting object.
*/
Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context);
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterLookup.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterLookup.java (.../ConverterLookup.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterLookup.java (.../ConverterLookup.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003, 2004, 2005 Joe Walnes.
- * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007, 2013 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -13,7 +13,7 @@
/**
* Responsible for looking up the correct Converter implementation for a specific type.
- *
+ *
* @author Joe Walnes
* @see Converter
*/
@@ -22,9 +22,9 @@
/**
* Lookup a converter for a specific type.
*
- * This type may be any Class, including primitive and array types. It may also be null, signifying the value to be
- * converted is a null type.
+ * This type may be any Class, including primitive and array types. It may also be null, signifying
+ * the value to be converted is a null type.
*
*/
- Converter lookupConverterForType(Class> type);
+ Converter lookupConverterForType(Class type);
}
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterMatcher.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterMatcher.java (.../ConverterMatcher.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterMatcher.java (.../ConverterMatcher.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -11,8 +11,9 @@
package com.thoughtworks.xstream.converters;
/**
- * ConverterMatcher allows to match converters to classes by determining if a given type can be converted by the
- * converter instance. ConverterMatcher is the base interface of any converter.
+ * ConverterMatcher allows to match converters to classes by
+ * determining if a given type can be converted by the converter instance.
+ * ConverterMatcher is the base interface of any converter.
*
* @author Joe Walnes
* @author Jörg Schaible
@@ -24,10 +25,9 @@
public interface ConverterMatcher {
/**
- * Determines whether the converter can marshal a particular type.
- *
+ * Determines whether the converter can marshall a particular type.
* @param type the Class representing the object type to be converted
*/
- boolean canConvert(Class> type);
+ boolean canConvert(Class type);
-}
+}
\ No newline at end of file
Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/DataHolder.java
===================================================================
diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
--- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/DataHolder.java (.../DataHolder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
+++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/DataHolder.java (.../DataHolder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004 Joe Walnes.
- * Copyright (C) 2006, 2007, 2014 XStream Committers.
+ * Copyright (C) 2006, 2007 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -13,17 +13,15 @@
import java.util.Iterator;
-
/**
* Holds generic data, to be used as seen fit by the user.
- *
+ *
* @author Joe Walnes
*/
public interface DataHolder {
Object get(Object key);
-
void put(Object key, Object value);
+ Iterator keys();
- Iterator