spring-framework / org.springframework.oxm.support / AbstractMarshaller

AbstractMarshaller

abstract class AbstractMarshaller : Marshaller, Unmarshaller

Abstract implementation of the Marshaller and Unmarshaller interface. This implementation inspects the given Source or Result, and delegates further handling to overridable template methods.

Author
Arjen Poutsma

Author
Juergen Hoeller

Since
3.0

Constructors

<init>

AbstractMarshaller()

Abstract implementation of the Marshaller and Unmarshaller interface. This implementation inspects the given Source or Result, and delegates further handling to overridable template methods.

Functions

isProcessExternalEntities

open fun isProcessExternalEntities(): Boolean

Returns the configured value for whether XML external entities are allowed.

isSupportDtd

open fun isSupportDtd(): Boolean

Whether DTD parsing is supported.

marshal

fun marshal(graph: Any, result: Result): Unit

Marshals the object graph with the given root into the provided javax.xml.transform.Result.

This implementation inspects the given result, and calls marshalDomResult, marshalSaxResult, or marshalStreamResult.

setProcessExternalEntities

open fun setProcessExternalEntities(processExternalEntities: Boolean): Unit

Indicates whether external XML entities are processed when unmarshalling.

Default is false, meaning that external entities are not resolved. Note that processing of external entities will only be enabled/disabled when the Source passed to #unmarshal(Source) is a SAXSource or StreamSource. It has no effect for DOMSource or StAXSource instances.

Note: setting this option to true also automatically sets #setSupportDtd to true.

setSupportDtd

open fun setSupportDtd(supportDtd: Boolean): Unit

Indicates whether DTD parsing should be supported.

Default is false meaning that DTD is disabled.

unmarshal

fun unmarshal(source: Source): Any

Unmarshals the given provided javax.xml.transform.Source into an object graph.

This implementation inspects the given result, and calls unmarshalDomSource, unmarshalSaxSource, or unmarshalStreamSource.

Inheritors

CastorMarshaller

open class CastorMarshaller : AbstractMarshaller, InitializingBean, BeanClassLoaderAware

Implementation of the Marshaller interface for Castor. By default, Castor does not require any further configuration, though setting target classes, target packages or providing a mapping file can be used to have more control over the behavior of Castor.

If a target class is specified using setTargetClass, the CastorMarshaller can only be used to unmarshal XML that represents that specific class. If you want to unmarshal multiple classes, you have to provide a mapping file using setMappingLocations.

Due to limitations of Castor's API, it is required to set the encoding used for writing to output streams. It defaults to UTF-8.

JibxMarshaller

open class JibxMarshaller : AbstractMarshaller, InitializingBean

Implementation of the Marshaller and Unmarshaller interfaces for JiBX.

The typical usage will be to set the targetClass and optionally the bindingName property on this bean.

XStreamMarshaller

open class XStreamMarshaller : AbstractMarshaller, BeanClassLoaderAware, InitializingBean

Implementation of the 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.5 or higher, as of Spring 4.3. Note that XStream construction has been reworked in 4.0, with the stream driver and the class loader getting passed into XStream itself now.