Marshaller interface for XStream.
By default, XStream does not require any further configuration and can (un)marshal
any class on the classpath. As such, it is not recommended to use the
XStreamMarshaller to unmarshal XML from external sources (i.e. the Web),
as this can result in security vulnerabilities. If you do use the
XStreamMarshaller to unmarshal external XML, set the
supportedClasses and
converters properties (possibly using
a CatchAllConverter) or override the customizeXStream(XStream)
method to make sure it only accepts the classes you want it to support.
Due to XStream's API, it is required to set the encoding used for writing to
OutputStreams. It defaults to UTF-8.
Note
XStream is an XML serialization library, not a data binding library. Therefore, it has limited namespace support. As such, it is rather unsuitable for usage within Web Services.
This marshaller requires XStream 1.4.7 or higher, as of Spring 5.2.17.
Note that XStream construction has been reworked in 4.0, with the
stream driver and the class loader getting passed into XStream itself now.
As of Spring Framework 6.0, the default HierarchicalStreamDriver is
a DomDriver that uses the configured encoding and NameCoder. The driver can be
changed via setStreamDriver(HierarchicalStreamDriver).
| Modifier and Type | Field and Description |
|---|---|
| private Map | |
| private Map | |
| private Class | |
| private boolean | |
| private ClassLoader | |
| private ConverterLookup | |
| private ConverterRegistry | |
| private ConverterMatcher[] | |
| public static final String | DEFAULT_ENCODING
The default encoding used for stream access: UTF-8. |
| private HierarchicalStreamDriver | |
| private String | |
| private Map | |
| private Map | |
| private Mapper | |
| private Class | |
| private MarshallingStrategy | |
| private Integer | |
| private NameCoder | |
| private Map | |
| private ReflectionProvider | |
| private HierarchicalStreamDriver | |
| private Class | |
| private TypePermission[] | |
| private Map | |
| private Class | |
| private final SingletonSupplier |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected XStream | buildXStream()
Build the native XStream delegate to be used by this marshaller,
delegating to |
| protected void | configureXStream(XStream
the xstream)XStream instanceConfigure the XStream instance with this marshaller's bean properties. |
| protected XStream | Returns: theXStream instanceConstruct an XStream instance, either using one of the standard constructors or creating a custom subclass. |
| protected XmlMappingException | Returns: the correspondingXmlMappingExceptionthe XStream exception that occurred ex, boolean indicates whether the exception occurs during marshalling ( marshalling)true),
or unmarshalling (false)Convert the given XStream exception to an appropriate exception from the
|
| protected void | customizeXStream(XStream
the xstream)XStream instanceTemplate to allow for customizing the given |
| private void | doMarshal(Object graph, HierarchicalStreamWriter streamWriter, DataHolder dataHolder)
Marshals the given graph to the given XStream HierarchicalStreamWriter. |
| private Object | doUnmarshal(HierarchicalStreamReader streamReader, DataHolder dataHolder)
Unmarshals the given graph to the given XStream HierarchicalStreamWriter. |
| private HierarchicalStreamDriver | |
| protected String | getDefaultEncoding()
Overrides org. Determine the default encoding to use for marshalling or unmarshalling from
a byte stream, or |
| public final XStream | |
| protected void | marshalDomNode(Object
the root of the object graph to marshal graph, Node the DOM node that will contain the result tree node)Implements abstract org. Abstract template method for marshalling the given object graph to a DOM |
| public void | marshalOutputStream(Object
the root of the object graph to marshal graph, OutputStream the outputStream)OutputStream to write toImplements abstract org. Abstract template method for marshalling the given object graph to a |
| public void | |
| protected void | marshalSaxHandlers(Object
the root of the object graph to marshal graph, ContentHandler the SAX contentHandler, LexicalHandler ContentHandlerthe SAX2 lexicalHandler)LexicalHandler. Can be null.Implements abstract org. Abstract template method for marshalling the given object graph to a SAX |
| public void | marshalWriter(Object
the root of the object graph to marshal graph, Writer the writer)Writer to write toImplements abstract org. Abstract template method for marshalling the given object graph to a |
| public void | |
| protected void | marshalXmlEventWriter(Object
the root of the object graph to marshal graph, XMLEventWriter the eventWriter)XMLEventWriter to write toImplements abstract org. Abstract template method for marshalling the given object to a StAX |
| protected void | marshalXmlStreamWriter(Object
the root of the object graph to marshal graph, XMLStreamWriter the streamWriter)XMLStreamWriter to write toImplements abstract org. Abstract template method for marshalling the given object to a StAX |
| public void | setAliases(Map<String, ?> aliases)
Set the alias/type map, consisting of string aliases mapped to classes. |
| public void | setAliasesByType(Map<String, ?> aliasesByType)
Set the aliases by type map, consisting of string aliases mapped to classes. |
| public void | setAnnotatedClasses(Class<?>... annotatedClasses)
Set annotated classes for which aliases will be read from class-level annotation metadata. |
| public void | |
| public void | setBeanClassLoader(ClassLoader
the owning class loader classLoader)Implements org. Callback that supplies the bean |
| public void | |
| public void | setConverterRegistry(ConverterRegistry converterRegistry)
Set a custom XStream |
| public void | setConverters(ConverterMatcher... converters)
Set the |
| public void | |
| public void | setFieldAliases(Map<String, String> fieldAliases)
Set the field alias/type map, consisting of field names. |
| public void | setImplicitCollections(Map<Class<?>, String> implicitCollections)
Specify implicit collection fields, as a Map consisting of |
| public void | |
| public void | setMapperWrappers(Class<? extends MapperWrapper>... mapperWrappers)
Set one or more custom XStream |
| public void | setMarshallingStrategy(MarshallingStrategy marshallingStrategy)
Set a custom XStream |
| public void | |
| public void | |
| public void | setOmittedFields(Map<Class<?>, String> omittedFields)
Specify omitted fields, as a Map consisting of |
| public void | setReflectionProvider(ReflectionProvider reflectionProvider)
Set a custom XStream |
| public void | setStreamDriver(HierarchicalStreamDriver streamDriver)
Set an XStream |
| public void | |
| public void | setTypePermissions(TypePermission... typePermissions)
Set XStream type permissions such as
|
| public void | |
| public void | |
| public boolean | supports(Class<?>
the class that this marshaller is being asked if it can marshal clazz)Implements org. Indicate whether this marshaller can marshal instances of the supplied type. |
| private Map | |
| protected Object | unmarshalDomNode(Node
the DOM node that contains the objects to be unmarshalled node)Implements abstract org. Abstract template method for unmarshalling from a given DOM |
| public Object | unmarshalInputStream(InputStream
the inputStream)InputStreamStream to read fromImplements abstract org. Abstract template method for unmarshalling from a given |
| public Object | |
| public Object | unmarshalReader(Reader
the reader)Reader to read fromImplements abstract org. Abstract template method for unmarshalling from a given |
| public Object | |
| protected Object | unmarshalSaxReader(XMLReader
the SAX xmlReader, InputSource XMLReader to parse withthe input source to parse from inputSource)Implements abstract org. Abstract template method for unmarshalling using a given SAX |
| protected Object | unmarshalStreamSource(StreamSource
the streamSource)StreamSourceOverrides org. Template method for handling |
| protected Object | unmarshalXmlEventReader(XMLEventReader
the eventReader)XMLEventReader to read fromImplements abstract org. Abstract template method for unmarshalling from a given Stax |
| protected Object | unmarshalXmlStreamReader(XMLStreamReader
the streamReader)XMLStreamReader to read fromImplements abstract org. Abstract template method for unmarshalling from a given Stax |