Class XStream
- java.lang.Object
-
- com.thoughtworks.xstream.XStream
-
public class XStream extends java.lang.ObjectSimple facade to XStream library, a Java-XML serialization tool.
ExampleXStream 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.
xstream.alias("my-thing", MyThing.class);
Converters
XStream contains a map of
Converterinstances, 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 thecom.thoughtworks.xstream.converters.extendedpackage and you can create your own by implementing theConverterinterface.
Examplexstream.registerConverter(new SqlTimestampConverter()); xstream.registerConverter(new DynamicProxyConverter());
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
ReflectionConverteras the fallback converter.
Examplexstream.registerConverter(new CustomDefaultConverter(), XStream.PRIORITY_VERY_LOW);
Object graphs
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():xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);(Default) Uses XPath relative references to signify duplicate references. This produces XML with the least clutter. xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);Uses XPath absolute references to signify duplicate references. This produces XML with the least clutter. xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);Uses XPath relative references to signify duplicate references. The XPath expression ensures that a single node only is selected always. xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);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. 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. 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 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
addImplicitCollectionmethods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXStream.InitializationExceptionDeprecated.As of 1.3, useInitializationExceptioninstead
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description XStream()Constructs a default XStream.XStream(ReflectionProvider reflectionProvider)Constructs an XStream with a specialReflectionProvider.XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver)Constructs an XStream with a specialHierarchicalStreamDriverandReflectionProvider.XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoaderReference)Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProviderand aClassLoaderReference.XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoaderReference, Mapper mapper)Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProvider, a preparedMapperchain and theClassLoaderReference.XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup, ConverterRegistry converterRegistry)Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProvider, a preparedMapperchain, theClassLoaderReferenceand an ownConverterLookupandConverterRegistry.privateXStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader, Mapper mapper, DefaultConverterLookup defaultConverterLookup)XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader)Deprecated.XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader, Mapper mapper)Deprecated.XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup, ConverterRegistry converterRegistry)XStream(ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver)Deprecated.As of 1.3, useXStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)insteadXStream(HierarchicalStreamDriver hierarchicalStreamDriver)Constructs an XStream with a specialHierarchicalStreamDriver.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDefaultImplementation(java.lang.Class defaultImplementation, java.lang.Class ofType)Associate a default implementation of a class with an object.voidaddImmutableType(java.lang.Class type)Deprecated.As of 1.4.9 useaddImmutableType(Class, boolean)voidaddImmutableType(java.lang.Class type, boolean isReferenceable)Add immutable types.private voidaddImmutableTypeDynamically(java.lang.String className, boolean isReferenceable)voidaddImplicitArray(java.lang.Class ownerType, java.lang.String fieldName)Adds an implicit array.voidaddImplicitArray(java.lang.Class ownerType, java.lang.String fieldName, java.lang.Class itemType)Adds an implicit array which is used for all items of the given itemType when the array type matches.voidaddImplicitArray(java.lang.Class ownerType, java.lang.String fieldName, java.lang.String itemName)Adds an implicit array which is used for all items of the given element name defined by itemName.voidaddImplicitCollection(java.lang.Class ownerType, java.lang.String fieldName)Adds a default implicit collection which is used for any unmapped XML tag.voidaddImplicitCollection(java.lang.Class ownerType, java.lang.String fieldName, java.lang.Class itemType)Adds implicit collection which is used for all items of the given itemType.voidaddImplicitCollection(java.lang.Class ownerType, java.lang.String fieldName, java.lang.String itemFieldName, java.lang.Class itemType)Adds implicit collection which is used for all items of the given element name defined by itemFieldName.voidaddImplicitMap(java.lang.Class ownerType, java.lang.String fieldName, java.lang.Class itemType, java.lang.String keyFieldName)Adds an implicit map.voidaddImplicitMap(java.lang.Class ownerType, java.lang.String fieldName, java.lang.String itemName, java.lang.Class itemType, java.lang.String keyFieldName)Adds an implicit map.voidaddPermission(TypePermission permission)Add a new security permission.voidalias(java.lang.String name, java.lang.Class type)Alias a Class to a shorter name to be used in XML elements.voidalias(java.lang.String name, java.lang.Class type, java.lang.Class defaultImplementation)Alias a Class to a shorter name to be used in XML elements.voidaliasAttribute(java.lang.Class definedIn, java.lang.String attributeName, java.lang.String alias)Create an alias for an attribute.voidaliasAttribute(java.lang.String alias, java.lang.String attributeName)Create an alias for an attributeprivate voidaliasDynamically(java.lang.String alias, java.lang.String className)voidaliasField(java.lang.String alias, java.lang.Class definedIn, java.lang.String fieldName)Create an alias for a field name.voidaliasPackage(java.lang.String name, java.lang.String pkgName)Alias a package to a shorter name to be used in XML elements.voidaliasSystemAttribute(java.lang.String alias, java.lang.String systemAttributeName)Create an alias for a system attribute.voidaliasType(java.lang.String name, java.lang.Class type)Alias a type to a shorter name to be used in XML elements.voidallowTypeHierarchy(java.lang.Class type)Add security permission for a type hierarchy.voidallowTypes(java.lang.Class[] types)Add security permission for explicit types.voidallowTypes(java.lang.String[] names)Add security permission for explicit types by name.voidallowTypesByRegExp(java.lang.String[] regexps)Add security permission for types matching one of the specified regular expressions.voidallowTypesByRegExp(java.util.regex.Pattern[] regexps)Add security permission for types matching one of the specified regular expressions.voidallowTypesByWildcard(java.lang.String[] patterns)Add security permission for types matching one of the specified wildcard patterns.voidautodetectAnnotations(boolean mode)Set the auto-detection mode of the AnnotationMapper.private MapperbuildMapper()private MapperbuildMapperDynamically(java.lang.String className, java.lang.Class[] constructorParamTypes, java.lang.Object[] constructorParamValues)java.io.ObjectInputStreamcreateObjectInputStream(HierarchicalStreamReader reader)Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.java.io.ObjectInputStreamcreateObjectInputStream(HierarchicalStreamReader reader, DataHolder dataHolder)Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.java.io.ObjectInputStreamcreateObjectInputStream(java.io.InputStream in)Creates an ObjectInputStream that deserializes a stream of objects from an InputStream using XStream.java.io.ObjectInputStreamcreateObjectInputStream(java.io.Reader xmlReader)Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(HierarchicalStreamWriter writer)Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(HierarchicalStreamWriter writer, java.lang.String rootNodeName)Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(HierarchicalStreamWriter writer, java.lang.String rootNodeName, DataHolder dataHolder)Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(java.io.OutputStream out)Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(java.io.OutputStream out, java.lang.String rootNodeName)Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(java.io.Writer writer)Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.java.io.ObjectOutputStreamcreateObjectOutputStream(java.io.Writer writer, java.lang.String rootNodeName)Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.voiddenyPermission(TypePermission permission)Add security permission denying another one.voiddenyTypeHierarchy(java.lang.Class type)Add security permission forbidding a type hierarchy.private voiddenyTypeHierarchyDynamically(java.lang.String className)voiddenyTypes(java.lang.Class[] types)Add security permission forbidding explicit types.voiddenyTypes(java.lang.String[] names)Add security permission forbidding explicit types by name.voiddenyTypesByRegExp(java.lang.String[] regexps)Add security permission forbidding types matching one of the specified regular expressions.voiddenyTypesByRegExp(java.util.regex.Pattern[] regexps)Add security permission forbidding types matching one of the specified regular expressions.voiddenyTypesByWildcard(java.lang.String[] patterns)Add security permission forbidding types matching one of the specified wildcard patterns.java.lang.ObjectfromXML(java.io.File file)Deserialize an object from a file.java.lang.ObjectfromXML(java.io.File file, java.lang.Object root)Deserialize an object from a file, populating the fields of the given root object instead of instantiating a new one.java.lang.ObjectfromXML(java.io.InputStream input)Deserialize an object from an XML InputStream.java.lang.ObjectfromXML(java.io.InputStream input, java.lang.Object root)Deserialize an object from an XML InputStream, populating the fields of the given root object instead of instantiating a new one.java.lang.ObjectfromXML(java.io.Reader reader)Deserialize an object from an XML Reader.java.lang.ObjectfromXML(java.io.Reader xml, java.lang.Object root)Deserialize an object from an XML Reader, populating the fields of the given root object instead of instantiating a new one.java.lang.ObjectfromXML(java.lang.String xml)Deserialize an object from an XML String.java.lang.ObjectfromXML(java.lang.String xml, java.lang.Object root)Deserialize an object from an XML String, populating the fields of the given root object instead of instantiating a new one.java.lang.ObjectfromXML(java.net.URL url)Deserialize an object from a URL.java.lang.ObjectfromXML(java.net.URL url, java.lang.Object root)Deserialize an object from a URL, populating the fields of the given root object instead of instantiating a new one.java.lang.ClassLoadergetClassLoader()Retrieve the ClassLoader XStream uses to load classes.ClassLoaderReferencegetClassLoaderReference()Retrieve the reference to this instance' ClassLoader.ConverterLookupgetConverterLookup()MappergetMapper()Retrieve theMapper.ReflectionProvidergetReflectionProvider()Retrieve theReflectionProviderin use.voidignoreUnknownElements()Ignore all unknown elements.voidignoreUnknownElements(java.lang.String pattern)Add pattern for unknown element names to ignore.voidignoreUnknownElements(java.util.regex.Pattern pattern)Add pattern for unknown element names to ignore.voidmarshal(java.lang.Object obj, HierarchicalStreamWriter writer)Serialize and object to a hierarchical data structure (such as XML).voidmarshal(java.lang.Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder)Serialize and object to a hierarchical data structure (such as XML).DataHoldernewDataHolder()Create a DataHolder that can be used to pass data to the converters.voidomitField(java.lang.Class definedIn, java.lang.String fieldName)Prevents a field from being serialized.voidprocessAnnotations(java.lang.Class type)Process the annotations of the given type and configure the XStream.voidprocessAnnotations(java.lang.Class[] types)Process the annotations of the given types and configure the XStream.voidregisterConverter(Converter converter)voidregisterConverter(Converter converter, int priority)voidregisterConverter(SingleValueConverter converter)voidregisterConverter(SingleValueConverter converter, int priority)private voidregisterConverterDynamically(java.lang.String className, int priority, java.lang.Class[] constructorParamTypes, java.lang.Object[] constructorParamValues)voidregisterLocalConverter(java.lang.Class definedIn, java.lang.String fieldName, Converter converter)Register a localConverterfor a field.voidregisterLocalConverter(java.lang.Class definedIn, java.lang.String fieldName, SingleValueConverter converter)Register a localSingleValueConverterfor a field.voidsetClassLoader(java.lang.ClassLoader classLoader)Change the ClassLoader XStream uses to load classes.voidsetCollectionUpdateLimit(int maxSeconds)Set time limit for adding elements to collections or maps.voidsetMarshallingStrategy(MarshallingStrategy marshallingStrategy)voidsetMode(int mode)Change mode for dealing with duplicate references.protected voidsetupAliases()protected voidsetupConverters()protected voidsetupDefaultImplementations()static voidsetupDefaultSecurity(XStream xstream)Deprecated.As of 1.4.18protected voidsetupImmutableTypes()private voidsetupMappers()protected voidsetupSecurity()java.lang.StringtoXML(java.lang.Object obj)Serialize an object to a pretty-printed XML String.voidtoXML(java.lang.Object obj, java.io.OutputStream out)Serialize an object to the given OutputStream as pretty-printed XML.voidtoXML(java.lang.Object obj, java.io.Writer out)Serialize an object to the given Writer as pretty-printed XML.java.lang.Objectunmarshal(HierarchicalStreamReader reader)Deserialize an object from a hierarchical data structure (such as XML).java.lang.Objectunmarshal(HierarchicalStreamReader reader, java.lang.Object root)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.java.lang.Objectunmarshal(HierarchicalStreamReader reader, java.lang.Object root, DataHolder dataHolder)Deserialize an object from a hierarchical data structure (such as XML).voiduseAttributeFor(java.lang.Class type)Use an attribute for an arbitrary type.voiduseAttributeFor(java.lang.Class definedIn, java.lang.String fieldName)Use an attribute for a field declared in a specific type.voiduseAttributeFor(java.lang.String fieldName, java.lang.Class type)Use an attribute for a field or a specific type.protected booleanuseXStream11XmlFriendlyMapper()Deprecated.As of 1.4.8protected MapperWrapperwrapMapper(MapperWrapper next)
-
-
-
Field Detail
-
collectionUpdateLimit
private int collectionUpdateLimit
-
reflectionProvider
private ReflectionProvider reflectionProvider
-
hierarchicalStreamDriver
private HierarchicalStreamDriver hierarchicalStreamDriver
-
classLoaderReference
private ClassLoaderReference classLoaderReference
-
marshallingStrategy
private MarshallingStrategy marshallingStrategy
-
converterLookup
private ConverterLookup converterLookup
-
converterRegistry
private ConverterRegistry converterRegistry
-
mapper
private Mapper mapper
-
packageAliasingMapper
private PackageAliasingMapper packageAliasingMapper
-
classAliasingMapper
private ClassAliasingMapper classAliasingMapper
-
fieldAliasingMapper
private FieldAliasingMapper fieldAliasingMapper
-
elementIgnoringMapper
private ElementIgnoringMapper elementIgnoringMapper
-
attributeAliasingMapper
private AttributeAliasingMapper attributeAliasingMapper
-
systemAttributeAliasingMapper
private SystemAttributeAliasingMapper systemAttributeAliasingMapper
-
attributeMapper
private AttributeMapper attributeMapper
-
defaultImplementationsMapper
private DefaultImplementationsMapper defaultImplementationsMapper
-
immutableTypesMapper
private ImmutableTypesMapper immutableTypesMapper
-
implicitCollectionMapper
private ImplicitCollectionMapper implicitCollectionMapper
-
localConversionMapper
private LocalConversionMapper localConversionMapper
-
securityMapper
private SecurityMapper securityMapper
-
annotationConfiguration
private AnnotationConfiguration annotationConfiguration
-
NO_REFERENCES
public static final int NO_REFERENCES
- See Also:
- Constant Field Values
-
ID_REFERENCES
public static final int ID_REFERENCES
- See Also:
- Constant Field Values
-
XPATH_RELATIVE_REFERENCES
public static final int XPATH_RELATIVE_REFERENCES
- See Also:
- Constant Field Values
-
XPATH_ABSOLUTE_REFERENCES
public static final int XPATH_ABSOLUTE_REFERENCES
- See Also:
- Constant Field Values
-
SINGLE_NODE_XPATH_RELATIVE_REFERENCES
public static final int SINGLE_NODE_XPATH_RELATIVE_REFERENCES
- See Also:
- Constant Field Values
-
SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES
public static final int SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES
- See Also:
- Constant Field Values
-
PRIORITY_VERY_HIGH
public static final int PRIORITY_VERY_HIGH
- See Also:
- Constant Field Values
-
PRIORITY_NORMAL
public static final int PRIORITY_NORMAL
- See Also:
- Constant Field Values
-
PRIORITY_LOW
public static final int PRIORITY_LOW
- See Also:
- Constant Field Values
-
PRIORITY_VERY_LOW
public static final int PRIORITY_VERY_LOW
- See Also:
- Constant Field Values
-
COLLECTION_UPDATE_LIMIT
public static final java.lang.String COLLECTION_UPDATE_LIMIT
- See Also:
- Constant Field Values
-
COLLECTION_UPDATE_SECONDS
public static final java.lang.String COLLECTION_UPDATE_SECONDS
- See Also:
- Constant Field Values
-
ANNOTATION_MAPPER_TYPE
private static final java.lang.String ANNOTATION_MAPPER_TYPE
- See Also:
- Constant Field Values
-
IGNORE_ALL
private static final java.util.regex.Pattern IGNORE_ALL
-
-
Constructor Detail
-
XStream
public XStream()
Constructs a default XStream.The instance will use the
XppDriveras default and tries to determine the best match for theReflectionProvideron its own.- Throws:
XStream.InitializationException- in case of an initialization problem
-
XStream
public XStream(ReflectionProvider reflectionProvider)
Constructs an XStream with a specialReflectionProvider.The instance will use the
XppDriveras default.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching reflection provider- Throws:
XStream.InitializationException- in case of an initialization problem
-
XStream
public XStream(HierarchicalStreamDriver hierarchicalStreamDriver)
Constructs an XStream with a specialHierarchicalStreamDriver.The instance will tries to determine the best match for the
ReflectionProvideron its own.- Parameters:
hierarchicalStreamDriver- the driver instance- Throws:
XStream.InitializationException- in case of an initialization problem
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver)
Constructs an XStream with a specialHierarchicalStreamDriverandReflectionProvider.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching ProviderhierarchicalStreamDriver- the driver instance- Throws:
XStream.InitializationException- in case of an initialization problem
-
XStream
public XStream(ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver)
Deprecated.As of 1.3, useXStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)insteadConstructs an XStream with a specialHierarchicalStreamDriver,ReflectionProviderand a preparedMapperchain.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching Providermapper- the instance with theMapperchain or null for the default chaindriver- the driver instance- Throws:
XStream.InitializationException- in case of an initialization problem
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoaderReference)
Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProviderand aClassLoaderReference.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching Providerdriver- the driver instanceclassLoaderReference- the reference to theClassLoaderto use- Throws:
XStream.InitializationException- in case of an initialization problem- Since:
- 1.4.5
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader)
Deprecated.Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProviderand theClassLoaderto use.- Throws:
XStream.InitializationException- in case of an initialization problem- Since:
- 1.3
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader, Mapper mapper)
Deprecated.Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProvider, a preparedMapperchain and theClassLoaderto use.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching Providerdriver- the driver instanceclassLoader- theClassLoaderto usemapper- the instance with theMapperchain or null for the default chain- Throws:
XStream.InitializationException- in case of an initialization problem- Since:
- 1.3
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoaderReference, Mapper mapper)
Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProvider, a preparedMapperchain and theClassLoaderReference.The
ClassLoaderReferenceshould also be used for theMapperchain.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching Providerdriver- the driver instanceclassLoaderReference- the reference to theClassLoaderto usemapper- the instance with theMapperchain or null for the default chain- Throws:
XStream.InitializationException- in case of an initialization problem- Since:
- 1.4.5
-
XStream
private XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader, Mapper mapper, DefaultConverterLookup defaultConverterLookup)
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup, ConverterRegistry converterRegistry)
Deprecated.Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProvider, a preparedMapperchain, theClassLoaderReferenceand an ownConverterLookupandConverterRegistry.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching Providerdriver- the driver instanceclassLoader- theClassLoaderto usemapper- the instance with theMapperchain or null for the default chainconverterLookup- the instance that is used to lookup the convertersconverterRegistry- an instance to manage the converter instances- Throws:
XStream.InitializationException- in case of an initialization problem- Since:
- 1.3
-
XStream
public XStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup, ConverterRegistry converterRegistry)
Constructs an XStream with a specialHierarchicalStreamDriver,ReflectionProvider, a preparedMapperchain, theClassLoaderReferenceand an ownConverterLookupandConverterRegistry.The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup should access the ConverterRegistry if you intent to register
Converterinstances with XStream facade or you are using annotations.- Parameters:
reflectionProvider- the reflection provider to use or null for best matching Providerdriver- the driver instanceclassLoaderReference- the reference to theClassLoaderto usemapper- the instance with theMapperchain or null for the default chainconverterLookup- the instance that is used to lookup the convertersconverterRegistry- an instance to manage the converter instances or null to prevent any further registry (including annotations)- Throws:
XStream.InitializationException- in case of an initialization problem- Since:
- 1.4.5
-
-
Method Detail
-
buildMapper
private Mapper buildMapper()
-
buildMapperDynamically
private Mapper buildMapperDynamically(java.lang.String className, java.lang.Class[] constructorParamTypes, java.lang.Object[] constructorParamValues)
-
wrapMapper
protected MapperWrapper wrapMapper(MapperWrapper next)
-
useXStream11XmlFriendlyMapper
protected boolean useXStream11XmlFriendlyMapper()
Deprecated.As of 1.4.8
-
setupMappers
private void setupMappers()
-
setupSecurity
protected void setupSecurity()
-
denyTypeHierarchyDynamically
private void denyTypeHierarchyDynamically(java.lang.String className)
-
setupDefaultSecurity
public static void setupDefaultSecurity(XStream xstream)
Deprecated.As of 1.4.18Setup the security framework of a XStream instance.This method was a pure helper method for XStream 1.4.10 to 1.4.17. It initialized an XStream instance with a whitelist of well-known and simply types of the Java runtime as it is done in XStream 1.4.18 by default. This method will do therefore nothing in XStream 1.4.18 or higher.
- Parameters:
xstream-- Since:
- 1.4.10
-
setupAliases
protected void setupAliases()
-
aliasDynamically
private void aliasDynamically(java.lang.String alias, java.lang.String className)
-
setupDefaultImplementations
protected void setupDefaultImplementations()
-
setupConverters
protected void setupConverters()
-
registerConverterDynamically
private void registerConverterDynamically(java.lang.String className, int priority, java.lang.Class[] constructorParamTypes, java.lang.Object[] constructorParamValues)
-
setupImmutableTypes
protected void setupImmutableTypes()
-
addImmutableTypeDynamically
private void addImmutableTypeDynamically(java.lang.String className, boolean isReferenceable)
-
setMarshallingStrategy
public void setMarshallingStrategy(MarshallingStrategy marshallingStrategy)
-
setCollectionUpdateLimit
public void setCollectionUpdateLimit(int maxSeconds)
Set time limit for adding elements to collections or maps. Manipulated content may be used to create recursive hash code calculations or sort operations. AnInputManipulationExceptionis thrown, if the summed up time to add elements to collections or maps exceeds the provided limit. Note, that the time to add an individual element is calculated in seconds, not milliseconds. However, attacks typically use objects with exponential growing calculation times.- Parameters:
maxSeconds- limit in seconds or 0 to disable check- Since:
- 1.4.19
-
toXML
public java.lang.String toXML(java.lang.Object obj)
Serialize an object to a pretty-printed XML String.- Throws:
XStreamException- if the object cannot be serialized
-
toXML
public void toXML(java.lang.Object obj, java.io.Writer out)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
-
toXML
public void toXML(java.lang.Object obj, java.io.OutputStream out)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
-
marshal
public void marshal(java.lang.Object obj, HierarchicalStreamWriter writer)Serialize and object to a hierarchical data structure (such as XML).- Throws:
XStreamException- if the object cannot be serialized
-
marshal
public void marshal(java.lang.Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder)Serialize and object to a hierarchical data structure (such as XML).- Parameters:
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
-
fromXML
public java.lang.Object fromXML(java.lang.String xml)
Deserialize an object from an XML String.- Throws:
XStreamException- if the object cannot be deserialized
-
fromXML
public java.lang.Object fromXML(java.io.Reader reader)
Deserialize an object from an XML Reader.- Throws:
XStreamException- if the object cannot be deserialized
-
fromXML
public java.lang.Object fromXML(java.io.InputStream input)
Deserialize an object from an XML InputStream.- Throws:
XStreamException- if the object cannot be deserialized
-
fromXML
public java.lang.Object fromXML(java.net.URL url)
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
-
fromXML
public java.lang.Object fromXML(java.io.File file)
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
-
fromXML
public java.lang.Object fromXML(java.lang.String xml, java.lang.Object root)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
-
fromXML
public java.lang.Object fromXML(java.io.Reader xml, java.lang.Object 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!- Throws:
XStreamException- if the object cannot be deserialized
-
fromXML
public java.lang.Object fromXML(java.net.URL url, java.lang.Object 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.- Throws:
XStreamException- if the object cannot be deserialized- Since:
- 1.4
-
fromXML
public java.lang.Object fromXML(java.io.File file, java.lang.Object 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.- Throws:
XStreamException- if the object cannot be deserialized- Since:
- 1.4
-
fromXML
public java.lang.Object fromXML(java.io.InputStream input, java.lang.Object root)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
-
unmarshal
public java.lang.Object unmarshal(HierarchicalStreamReader reader)
Deserialize an object from a hierarchical data structure (such as XML).- Throws:
XStreamException- if the object cannot be deserialized
-
unmarshal
public java.lang.Object unmarshal(HierarchicalStreamReader reader, java.lang.Object root)
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
-
unmarshal
public java.lang.Object unmarshal(HierarchicalStreamReader reader, java.lang.Object root, DataHolder dataHolder)
Deserialize an object from a hierarchical data structure (such as XML).- Parameters:
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!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
-
alias
public void alias(java.lang.String name, java.lang.Class type)Alias a Class to a shorter name to be used in XML elements.- Parameters:
name- Short nametype- Type to be aliased- Throws:
XStream.InitializationException- if noClassAliasingMapperis available
-
aliasType
public void aliasType(java.lang.String name, java.lang.Class 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.- Parameters:
name- Short nametype- Type to be aliased- Throws:
XStream.InitializationException- if noClassAliasingMapperis available- Since:
- 1.2
-
alias
public void alias(java.lang.String name, java.lang.Class type, java.lang.Class defaultImplementation)Alias a Class to a shorter name to be used in XML elements.- Parameters:
name- Short nametype- Type to be aliaseddefaultImplementation- Default implementation of type to use if no other specified.- Throws:
XStream.InitializationException- if noDefaultImplementationsMapperor noClassAliasingMapperis available
-
aliasPackage
public void aliasPackage(java.lang.String name, java.lang.String pkgName)Alias a package to a shorter name to be used in XML elements.- Parameters:
name- Short namepkgName- package to be aliased- Throws:
XStream.InitializationException- if noDefaultImplementationsMapperor noPackageAliasingMapperis available- Since:
- 1.3.1
-
aliasField
public void aliasField(java.lang.String alias, java.lang.Class definedIn, java.lang.String fieldName)Create an alias for a field name.- Parameters:
alias- the alias itselfdefinedIn- the type that declares the fieldfieldName- the name of the field- Throws:
XStream.InitializationException- if noFieldAliasingMapperis available
-
aliasAttribute
public void aliasAttribute(java.lang.String alias, java.lang.String attributeName)Create an alias for an attribute- Parameters:
alias- the alias itselfattributeName- the name of the attribute- Throws:
XStream.InitializationException- if noAttributeAliasingMapperis available
-
aliasSystemAttribute
public void aliasSystemAttribute(java.lang.String alias, java.lang.String systemAttributeName)Create an alias for a system attribute. XStream will not write a system attribute if its alias is set tonull. 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.- Parameters:
alias- the alias itself (may benull)systemAttributeName- the name of the system attribute- Throws:
XStream.InitializationException- if noSystemAttributeAliasingMapperis available- Since:
- 1.3.1
-
aliasAttribute
public void aliasAttribute(java.lang.Class definedIn, java.lang.String attributeName, java.lang.String alias)Create an alias for an attribute.- Parameters:
definedIn- the type where the attribute is definedattributeName- the name of the attributealias- the alias itself- Throws:
XStream.InitializationException- if noAttributeAliasingMapperis available- Since:
- 1.2.2
-
useAttributeFor
public void useAttributeFor(java.lang.String fieldName, java.lang.Class type)Use an attribute for a field or a specific type.- Parameters:
fieldName- the name of the fieldtype- the Class of the type to be rendered as XML attribute- Throws:
XStream.InitializationException- if noAttributeMapperis available- Since:
- 1.2
-
useAttributeFor
public void useAttributeFor(java.lang.Class definedIn, java.lang.String fieldName)Use an attribute for a field declared in a specific type.- Parameters:
fieldName- the name of the fielddefinedIn- the Class containing such field- Throws:
XStream.InitializationException- if noAttributeMapperis available- Since:
- 1.2.2
-
useAttributeFor
public void useAttributeFor(java.lang.Class type)
Use an attribute for an arbitrary type.- Parameters:
type- the Class of the type to be rendered as XML attribute- Throws:
XStream.InitializationException- if noAttributeMapperis available- Since:
- 1.2
-
addDefaultImplementation
public void addDefaultImplementation(java.lang.Class defaultImplementation, java.lang.Class ofType)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.- Parameters:
defaultImplementation-ofType-- Throws:
XStream.InitializationException- if noDefaultImplementationsMapperis available
-
addImmutableType
public void addImmutableType(java.lang.Class type)
Deprecated.As of 1.4.9 useaddImmutableType(Class, boolean)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:
XStream.InitializationException- if noImmutableTypesMapperis available
-
addImmutableType
public void addImmutableType(java.lang.Class type, boolean isReferenceable)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.
- Parameters:
isReferenceable-trueif support at deserialization time is required for compatibility at the cost of a higher memory footprint,falseotherwise- Throws:
XStream.InitializationException- if noImmutableTypesMapperis available- Since:
- 1.4.9
-
registerConverter
public void registerConverter(Converter converter)
-
registerConverter
public void registerConverter(Converter converter, int priority)
-
registerConverter
public void registerConverter(SingleValueConverter converter)
-
registerConverter
public void registerConverter(SingleValueConverter converter, int priority)
-
registerLocalConverter
public void registerLocalConverter(java.lang.Class definedIn, java.lang.String fieldName, Converter converter)Register a localConverterfor a field.- Parameters:
definedIn- the class type the field is defined infieldName- the field nameconverter- the converter to use- Since:
- 1.3
-
registerLocalConverter
public void registerLocalConverter(java.lang.Class definedIn, java.lang.String fieldName, SingleValueConverter converter)Register a localSingleValueConverterfor a field.- Parameters:
definedIn- the class type the field is defined infieldName- the field nameconverter- the converter to use- Since:
- 1.3
-
getMapper
public Mapper getMapper()
Retrieve theMapper. This is by default a chain ofMapperWrappers.- Returns:
- the mapper
- Since:
- 1.2
-
getReflectionProvider
public ReflectionProvider getReflectionProvider()
Retrieve theReflectionProviderin use.- Returns:
- the mapper
- Since:
- 1.2.1
-
getConverterLookup
public ConverterLookup getConverterLookup()
-
setMode
public void setMode(int mode)
Change mode for dealing with duplicate references. Valid values areXPATH_ABSOLUTE_REFERENCES,XPATH_RELATIVE_REFERENCES,XStream.ID_REFERENCESandXStream.NO_REFERENCES.- Throws:
java.lang.IllegalArgumentException- if the mode is not one of the declared types- See Also:
XPATH_ABSOLUTE_REFERENCES,XPATH_RELATIVE_REFERENCES,ID_REFERENCES,NO_REFERENCES
-
addImplicitCollection
public void addImplicitCollection(java.lang.Class ownerType, java.lang.String fieldName)Adds a default implicit collection which is used for any unmapped XML tag.- Parameters:
ownerType- class owning the implicit collectionfieldName- 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.
-
addImplicitCollection
public void addImplicitCollection(java.lang.Class ownerType, java.lang.String fieldName, java.lang.Class itemType)Adds implicit collection which is used for all items of the given itemType.- Parameters:
ownerType- class owning the implicit collectionfieldName- 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.itemType- type of the items to be part of this collection- Throws:
XStream.InitializationException- if noImplicitCollectionMapperis available
-
addImplicitCollection
public void addImplicitCollection(java.lang.Class ownerType, java.lang.String fieldName, java.lang.String itemFieldName, java.lang.Class itemType)Adds implicit collection which is used for all items of the given element name defined by itemFieldName.- Parameters:
ownerType- class owning the implicit collectionfieldName- 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.itemFieldName- element name of the implicit collectionitemType- item type to be aliases be the itemFieldName- Throws:
XStream.InitializationException- if noImplicitCollectionMapperis available
-
addImplicitArray
public void addImplicitArray(java.lang.Class ownerType, java.lang.String fieldName)Adds an implicit array.- Parameters:
ownerType- class owning the implicit arrayfieldName- name of the array field- Since:
- 1.4
-
addImplicitArray
public void addImplicitArray(java.lang.Class ownerType, java.lang.String fieldName, java.lang.Class itemType)Adds an implicit array which is used for all items of the given itemType when the array type matches.- Parameters:
ownerType- class owning the implicit arrayfieldName- name of the array field in the ownerTypeitemType- type of the items to be part of this array- Throws:
XStream.InitializationException- if noImplicitCollectionMapperis available or the array type does not match the itemType- Since:
- 1.4
-
addImplicitArray
public void addImplicitArray(java.lang.Class ownerType, java.lang.String fieldName, java.lang.String itemName)Adds an implicit array which is used for all items of the given element name defined by itemName.- Parameters:
ownerType- class owning the implicit arrayfieldName- name of the array field in the ownerTypeitemName- alias name of the items- Throws:
XStream.InitializationException- if noImplicitCollectionMapperis available- Since:
- 1.4
-
addImplicitMap
public void addImplicitMap(java.lang.Class ownerType, java.lang.String fieldName, java.lang.Class itemType, java.lang.String keyFieldName)Adds an implicit map.- Parameters:
ownerType- class owning the implicit mapfieldName- 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.itemType- type of the items to be part of this map as valuekeyFieldName- the name of the field of the itemType that is used for the key in the map- Since:
- 1.4
-
addImplicitMap
public void addImplicitMap(java.lang.Class ownerType, java.lang.String fieldName, java.lang.String itemName, java.lang.Class itemType, java.lang.String keyFieldName)Adds an implicit map.- Parameters:
ownerType- class owning the implicit mapfieldName- 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.itemName- alias name of the itemsitemType- type of the items to be part of this map as valuekeyFieldName- the name of the field of the itemType that is used for the key in the map- Since:
- 1.4
-
newDataHolder
public DataHolder newDataHolder()
Create a DataHolder that can be used to pass data to the converters. The DataHolder is provided with a call tomarshal(Object, HierarchicalStreamWriter, DataHolder),unmarshal(HierarchicalStreamReader, Object, DataHolder),createObjectInputStream(HierarchicalStreamReader, DataHolder)orcreateObjectOutputStream(HierarchicalStreamWriter, String, DataHolder).- Returns:
- a new
DataHolder
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(java.io.Writer writer) throws java.io.IOExceptionCreates 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
createObjectOutputStream(java.io.Writer, String).- Throws:
java.io.IOException- Since:
- 1.0.3
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer) throws java.io.IOException
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
createObjectOutputStream(java.io.Writer, String).- Throws:
java.io.IOException- Since:
- 1.0.3
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(java.io.Writer writer, java.lang.String rootNodeName) throws java.io.IOExceptionCreates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.- Throws:
java.io.IOException- Since:
- 1.0.3
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(java.io.OutputStream out) throws java.io.IOExceptionCreates 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
createObjectOutputStream(java.io.Writer, String).- Throws:
java.io.IOException- Since:
- 1.3
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(java.io.OutputStream out, java.lang.String rootNodeName) throws java.io.IOExceptionCreates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream.- Throws:
java.io.IOException- Since:
- 1.3
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer, java.lang.String rootNodeName) throws java.io.IOException
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.
It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will be incomplete.
Example
ObjectOutputStream out = xstream.createObjectOutputStream(aWriter, "things"); out.writeInt(123); out.writeObject("Hello"); out.writeObject(someObject) out.close();- Parameters:
writer- The writer to serialize the objects to.rootNodeName- The name of the root node enclosing the stream of objects.- Throws:
java.io.IOException- Since:
- 1.0.3
- See Also:
createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectOutputStream
public java.io.ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer, java.lang.String rootNodeName, DataHolder dataHolder) throws java.io.IOException
Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.- Throws:
java.io.IOException- Since:
- 1.4.10
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
createObjectInputStream
public java.io.ObjectInputStream createObjectInputStream(java.io.Reader xmlReader) throws java.io.IOExceptionCreates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.- Throws:
java.io.IOException- Since:
- 1.0.3
- See Also:
createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader),createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
-
createObjectInputStream
public java.io.ObjectInputStream createObjectInputStream(java.io.InputStream in) throws java.io.IOExceptionCreates an ObjectInputStream that deserializes a stream of objects from an InputStream using XStream.- Throws:
java.io.IOException- Since:
- 1.3
- See Also:
createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader),createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
-
createObjectInputStream
public java.io.ObjectInputStream createObjectInputStream(HierarchicalStreamReader reader) throws java.io.IOException
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();
- Throws:
java.io.IOException- Since:
- 1.0.3
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
-
createObjectInputStream
public java.io.ObjectInputStream createObjectInputStream(HierarchicalStreamReader reader, DataHolder dataHolder) throws java.io.IOException
Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.- Throws:
java.io.IOException- Since:
- 1.4.10
- See Also:
createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String),createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
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
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Retrieve the ClassLoader XStream uses to load classes.- Since:
- 1.1.1
-
getClassLoaderReference
public ClassLoaderReference getClassLoaderReference()
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.- Returns:
- the reference
- Since:
- 1.4.5
-
omitField
public void omitField(java.lang.Class definedIn, java.lang.String fieldName)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.- Throws:
XStream.InitializationException- if noElementIgnoringMapperis available- Since:
- 1.1.3
-
ignoreUnknownElements
public void ignoreUnknownElements()
Ignore all unknown elements.- Since:
- 1.4.5
-
ignoreUnknownElements
public void ignoreUnknownElements(java.lang.String pattern)
Add pattern for unknown element names to ignore.- Parameters:
pattern- the name pattern as regular expression- Since:
- 1.4.5
-
ignoreUnknownElements
public void ignoreUnknownElements(java.util.regex.Pattern pattern)
Add pattern for unknown element names to ignore.- Parameters:
pattern- the name pattern as regular expression- Since:
- 1.4.5
-
processAnnotations
public void processAnnotations(java.lang.Class[] types)
Process the annotations of the given types and configure the XStream.- Parameters:
types- the types with XStream annotations- Since:
- 1.3
-
processAnnotations
public void processAnnotations(java.lang.Class type)
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.- Parameters:
type- the type with XStream annotations- Since:
- 1.3
-
autodetectAnnotations
public void autodetectAnnotations(boolean mode)
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!- Parameters:
mode-trueif annotations are auto-detected- Since:
- 1.3
-
addPermission
public void addPermission(TypePermission permission)
Add a new security permission.Permissions are evaluated in the added sequence. An instance of
NoTypePermissionorAnyTypePermissionwill implicitly wipe any existing permission.- Parameters:
permission- the permission to add- Since:
- 1.4.7
-
allowTypes
public void allowTypes(java.lang.String[] names)
Add security permission for explicit types by name.- Parameters:
names- the type names to allow- Since:
- 1.4.7
-
allowTypes
public void allowTypes(java.lang.Class[] types)
Add security permission for explicit types.- Parameters:
types- the types to allow- Since:
- 1.4.7
-
allowTypeHierarchy
public void allowTypeHierarchy(java.lang.Class type)
Add security permission for a type hierarchy.- Parameters:
type- the base type to allow- Since:
- 1.4.7
-
allowTypesByRegExp
public void allowTypesByRegExp(java.lang.String[] regexps)
Add security permission for types matching one of the specified regular expressions.- Parameters:
regexps- the regular expressions to allow type names- Since:
- 1.4.7
-
allowTypesByRegExp
public void allowTypesByRegExp(java.util.regex.Pattern[] regexps)
Add security permission for types matching one of the specified regular expressions.- Parameters:
regexps- the regular expressions to allow type names- Since:
- 1.4.7
-
allowTypesByWildcard
public void allowTypesByWildcard(java.lang.String[] patterns)
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.**'
- Parameters:
patterns- the patterns to allow type names- Since:
- 1.4.7
-
denyPermission
public void denyPermission(TypePermission permission)
Add security permission denying another one.- Parameters:
permission- the permission to deny- Since:
- 1.4.7
-
denyTypes
public void denyTypes(java.lang.String[] names)
Add security permission forbidding explicit types by name.- Parameters:
names- the type names to forbid- Since:
- 1.4.7
-
denyTypes
public void denyTypes(java.lang.Class[] types)
Add security permission forbidding explicit types.- Parameters:
types- the types to forbid- Since:
- 1.4.7
-
denyTypeHierarchy
public void denyTypeHierarchy(java.lang.Class type)
Add security permission forbidding a type hierarchy.- Parameters:
type- the base type to forbid- Since:
- 1.4.7
-
denyTypesByRegExp
public void denyTypesByRegExp(java.lang.String[] regexps)
Add security permission forbidding types matching one of the specified regular expressions.- Parameters:
regexps- the regular expressions to forbid type names- Since:
- 1.4.7
-
denyTypesByRegExp
public void denyTypesByRegExp(java.util.regex.Pattern[] regexps)
Add security permission forbidding types matching one of the specified regular expressions.- Parameters:
regexps- the regular expressions to forbid type names- Since:
- 1.4.7
-
denyTypesByWildcard
public void denyTypesByWildcard(java.lang.String[] patterns)
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.**'
- Parameters:
patterns- the patterns to forbid names- Since:
- 1.4.7
-
-