spring-framework / org.springframework.oxm.jaxb / Jaxb2Marshaller

Jaxb2Marshaller

open class Jaxb2Marshaller : MimeMarshaller, MimeUnmarshaller, GenericMarshaller, GenericUnmarshaller, BeanClassLoaderAware, InitializingBean

Implementation of the GenericMarshaller interface for JAXB 2.2.

The typical usage will be to set either the "contextPath" or the "classesToBeBound" property on this bean, possibly customize the marshaller and unmarshaller by setting properties, schemas, adapters, and listeners, and to refer to it.

Author
Arjen Poutsma

Author
Juergen Hoeller

Author
Rossen Stoyanchev

Since
3.0

See Also
#setContextPath(String)#setClassesToBeBound(Class[])#setJaxbContextProperties(Map)#setMarshallerProperties(Map)#setUnmarshallerProperties(Map)#setSchema(Resource)#setSchemas(Resource[])#setMarshallerListener(javax.xml.bind.Marshaller.Listener)#setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener)#setAdapters(XmlAdapter[])

Constructors

<init>

Jaxb2Marshaller()

Implementation of the GenericMarshaller interface for JAXB 2.2.

The typical usage will be to set either the "contextPath" or the "classesToBeBound" property on this bean, possibly customize the marshaller and unmarshaller by setting properties, schemas, adapters, and listeners, and to refer to it.

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

getClassesToBeBound

open fun getClassesToBeBound(): Array<Class<*>>

Return the list of Java classes to be recognized by a newly created JAXBContext.

getContextPath

open fun getContextPath(): String

Return the JAXB context path.

getJaxbContext

open fun getJaxbContext(): JAXBContext

Return the JAXBContext used by this marshaller, lazily building it if necessary.

getPackagesToScan

open fun getPackagesToScan(): Array<String>

Return the packages to search for JAXB2 annotations.

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

open fun marshal(graph: Any, result: Result): Unit
open fun marshal(graph: Any, result: Result, mimeContainer: MimeContainer): Unit

setAdapters

open fun setAdapters(vararg adapters: XmlAdapter<*, *>): Unit

Specify the XmlAdapters to be registered with the JAXB Marshaller and Unmarshaller

setBeanClassLoader

open fun setBeanClassLoader(classLoader: ClassLoader): Unit

setCheckForXmlRootElement

open fun setCheckForXmlRootElement(checkForXmlRootElement: Boolean): Unit

Specify whether the #supports(Class) should check for XmlRootElement annotations.

Default is true, meaning that supports(Class) will check for this annotation. However, some JAXB implementations (i.e. EclipseLink MOXy) allow for defining the bindings in an external definition file, thus keeping the classes annotations free. Setting this property to false supports these JAXB implementations.

setClassesToBeBound

open fun setClassesToBeBound(vararg classesToBeBound: Class<*>): Unit

Set the list of Java classes to be recognized by a newly created JAXBContext.

Setting either this property, "contextPath" or "packagesToScan" is required.

setContextPath

open fun setContextPath(contextPath: String): Unit

Set a JAXB context path.

Setting either this property, "classesToBeBound" or "packagesToScan" is required.

setContextPaths

open fun setContextPaths(vararg contextPaths: String): Unit

Set multiple JAXB context paths. The given array of context paths gets converted to a colon-delimited string, as supported by JAXB.

setJaxbContextProperties

open fun setJaxbContextProperties(jaxbContextProperties: MutableMap<String, *>): Unit

Set the JAXBContext properties. These implementation-specific properties will be set on the underlying JAXBContext.

setLazyInit

open fun setLazyInit(lazyInit: Boolean): Unit

Set whether to lazily initialize the JAXBContext for this marshaller. Default is false to initialize on startup; can be switched to true.

Early initialization just applies if #afterPropertiesSet() is called.

setMappedClass

open fun setMappedClass(mappedClass: Class<*>): Unit

Specify a JAXB mapped class for partial unmarshalling.

setMarshallerListener

open fun setMarshallerListener(marshallerListener: Listener): Unit

Specify the Marshaller.Listener to be registered with the JAXB Marshaller.

setMarshallerProperties

open fun setMarshallerProperties(properties: MutableMap<String, *>): Unit

Set the JAXB Marshaller properties. These properties will be set on the underlying JAXB Marshaller, and allow for features such as indentation.

setMtomEnabled

open fun setMtomEnabled(mtomEnabled: Boolean): Unit

Specify whether MTOM support should be enabled or not. Default is false: marshalling using XOP/MTOM not being enabled.

setPackagesToScan

open fun setPackagesToScan(vararg packagesToScan: String): Unit

Set the packages to search for classes with JAXB2 annotations in the classpath. This is using a Spring-bases search and therefore analogous to Spring's component-scan feature (org.springframework.context.annotation.ClassPathBeanDefinitionScanner).

Setting either this property, "contextPath" or "classesToBeBound" is required.

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.

setSchema

open fun setSchema(schemaResource: Resource): Unit

Set the schema resource to use for validation.

setSchemaLanguage

open fun setSchemaLanguage(schemaLanguage: String): Unit

Set the schema language. Default is the W3C XML Schema: http://www.w3.org/2001/XMLSchema".

setSchemaResourceResolver

open fun setSchemaResourceResolver(schemaResourceResolver: LSResourceResolver): Unit

Set the resource resolver, as used to load the schema resources.

setSchemas

open fun setSchemas(vararg schemaResources: Resource): Unit

Set the schema resources to use for validation.

setSupportDtd

open fun setSupportDtd(supportDtd: Boolean): Unit

Indicates whether DTD parsing should be supported.

Default is false meaning that DTD is disabled.

setSupportJaxbElementClass

open fun setSupportJaxbElementClass(supportJaxbElementClass: Boolean): Unit

Specify whether the #supports(Class) returns true for the JAXBElement class.

Default is false, meaning that supports(Class) always returns false for JAXBElement classes (though #supports(Type) can return true, since it can obtain the type parameters of JAXBElement).

This property is typically enabled in combination with usage of classes like org.springframework.web.servlet.view.xml.MarshallingView, since the ModelAndView does not offer type parameter information at runtime.

setUnmarshallerListener

open fun setUnmarshallerListener(unmarshallerListener: Listener): Unit

Set the Unmarshaller.Listener to be registered with the JAXB Unmarshaller.

setUnmarshallerProperties

open fun setUnmarshallerProperties(properties: MutableMap<String, *>): Unit

Set the JAXB Unmarshaller properties. These properties will be set on the underlying JAXB Unmarshaller.

setValidationEventHandler

open fun setValidationEventHandler(validationEventHandler: ValidationEventHandler): Unit

Set the JAXB validation event handler. This event handler will be called by JAXB if any validation errors are encountered during calls to any of the marshal APIs.

supports

open fun supports(clazz: Class<*>): Boolean
open fun supports(genericType: Type): Boolean

unmarshal

open fun unmarshal(source: Source): Any
open fun unmarshal(source: Source, mimeContainer: MimeContainer): Any