Top Description Inners Fields Constructors Methods
org.springframework.oxm.jaxb

public Class Jaxb2Marshaller

extends Object
implements MimeMarshaller, MimeUnmarshaller, GenericMarshaller, GenericUnmarshaller, BeanClassLoaderAware, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.Aware, org.springframework.oxm.GenericUnmarshaller, org.springframework.oxm.Unmarshaller, org.springframework.oxm.GenericMarshaller, org.springframework.oxm.Marshaller, org.springframework.oxm.mime.MimeUnmarshaller, org.springframework.oxm.mime.MimeMarshaller
Imports
java.awt.Image, java.io.ByteArrayInputStream, .IOException, .InputStream, .OutputStream, .StringReader, java.lang.reflect.GenericArrayType, .ParameterizedType, .Type, java.math.BigDecimal, .BigInteger, java.net.URI, .URISyntaxException, .URLDecoder, .URLEncoder, java.nio.charset.StandardCharsets, java.util.Arrays, .Calendar, .Date, .Map, .UUID, javax.xml.XMLConstants, javax.xml.datatype.Duration, .XMLGregorianCalendar, javax.xml.namespace.QName, javax.xml.parsers.ParserConfigurationException, .SAXParser, .SAXParserFactory, javax.xml.stream.XMLEventReader, .XMLEventWriter, .XMLStreamReader, .XMLStreamWriter, javax.xml.transform.Result, .Source, javax.xml.transform.dom.DOMSource, javax.xml.transform.sax.SAXSource, javax.xml.transform.stax.StAXSource, javax.xml.transform.stream.StreamSource, javax.xml.validation.Schema, .SchemaFactory, jakarta.activation.DataHandler, .DataSource, jakarta.xml.bind.JAXBContext, .JAXBElement, .JAXBException, .MarshalException, .Marshaller, .UnmarshalException, .Unmarshaller, .ValidationEventHandler, .ValidationException, jakarta.xml.bind.annotation.XmlRootElement, jakarta.xml.bind.annotation.adapters.XmlAdapter, jakarta.xml.bind.attachment.AttachmentMarshaller, .AttachmentUnmarshaller, org.apache.commons.logging.Log, .LogFactory, org.w3c.dom.ls.LSResourceResolver, org.xml.sax.EntityResolver, .InputSource, .SAXException, .XMLReader, org.springframework.beans.factory.BeanClassLoaderAware, .InitializingBean, org.springframework.core.annotation.AnnotationUtils, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.oxm.GenericMarshaller, .GenericUnmarshaller, .MarshallingFailureException, .UncategorizedMappingException, .UnmarshallingFailureException, .ValidationFailureException, .XmlMappingException, org.springframework.oxm.mime.MimeContainer, .MimeMarshaller, .MimeUnmarshaller, org.springframework.oxm.support.SaxResourceUtils, org.springframework.util.Assert, .ClassUtils, .FileCopyUtils, .ObjectUtils, .ResourceUtils, .StringUtils, org.springframework.util.xml.StaxUtils

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.

Authors
Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sam Brannen
Since
3.0
See Also
setContextPath, setClassesToBeBound, setJaxbContextProperties, setMarshallerProperties, setUnmarshallerProperties, setSchema, setSchemas, setMarshallerListener, setUnmarshallerListener, setAdapters

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Jaxb2Marshaller.ByteArrayDataSource

DataSource that wraps around a byte array.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private XmlAdapter<?, ?>[]
private ClassLoader
private boolean
private static final String
private Class<?>[]
private String
private volatile JAXBContext
private final Object
private Map<String, ?>
private boolean
protected final Log
logger

Logger available to subclasses.

private Class<?>
private Marshaller.Listener
private Map<String, ?>
private boolean
private static final EntityResolver
private String[]
private boolean
private Schema
private String
private LSResourceResolver
private Resource[]
private boolean
private boolean
private Unmarshaller.Listener
private Map<String, ?>
private ValidationEventHandler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

protected XmlMappingException

Returns:

the corresponding XmlMappingException
convertJaxbException
(JAXBException
JAXBException that occurred
ex
)

Convert the given JAXBException to an appropriate exception from the org.springframework.oxm hierarchy.

private JAXBContext
createJaxbContextFromClasses(Class<?>... classesToBeBound)

private JAXBContext
private JAXBContext
public Marshaller
createMarshaller()

Return a newly created JAXB marshaller.

public Unmarshaller
createUnmarshaller()

Return a newly created JAXB unmarshaller.

public Class<?>[]
getClassesToBeBound()

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

public String
getContextPath()

Return the JAXB context path.

public JAXBContext
getJaxbContext()

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

public String[]
getPackagesToScan()

Return the packages to search for JAXB2 annotations.

protected void
initJaxbMarshaller(Marshaller marshaller)

Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.

protected void
initJaxbUnmarshaller(Unmarshaller unmarshaller)

Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.

private boolean
isPrimitiveWrapper(Class<?> clazz)

Checks whether the given type is a primitive wrapper type.

public boolean
isProcessExternalEntities()

Return whether XML external entities are allowed.

private boolean
isStandardClass(Class<?> clazz)

Checks whether the given type is a standard class.

public boolean
isSupportDtd()

Return whether DTD parsing is supported.

private Schema
loadSchema(Resource[] resources, String schemaLanguage)

public void
marshal(Object
the root of the object graph to marshal
graph
,
Result
the result to marshal to
result
)

Implements org.springframework.oxm.Marshaller.marshal.

Marshal the object graph with the given root into the provided Result.

public void
marshal(Object
the root of the object graph to marshal
graph
,
Result
the result to marshal to
result
,
MimeContainer
the MIME container to write extracted binary content to
mimeContainer
)

Implements org.springframework.oxm.mime.MimeMarshaller.marshal.

Marshals the object graph with the given root into the provided Result, writing binary data to a MimeContainer.

private void
marshalStaxResult(Marshaller jaxbMarshaller, Object graph, Result staxResult)

private Source
public void
setAdapters(XmlAdapter<?, ?>... adapters)

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

public void
setBeanClassLoader(ClassLoader
the owning class loader
classLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

public void
setCheckForXmlRootElement(boolean checkForXmlRootElement)

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

public void
setClassesToBeBound(Class<?>... classesToBeBound)

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

public void
setContextPath(String contextPath)

Set a JAXB context path.

public void
setContextPaths(String... contextPaths)

Set multiple JAXB context paths.

public void
setJaxbContextProperties(Map<String, ?> jaxbContextProperties)

Set the JAXBContext properties.

public void
setLazyInit(boolean lazyInit)

Set whether to lazily initialize the JAXBContext for this marshaller.

public void
setMappedClass(Class<?> mappedClass)

Specify a JAXB mapped class for partial unmarshalling.

public void
setMarshallerListener(Marshaller.Listener marshallerListener)

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

public void
setMarshallerProperties(Map<String, ?>
the properties
properties
)

Set the JAXB Marshaller properties.

public void
setMtomEnabled(boolean mtomEnabled)

Specify whether MTOM support should be enabled or not.

public void
setPackagesToScan(String... packagesToScan)

Set the packages to search for classes with JAXB2 annotations in the classpath.

public void
setProcessExternalEntities(boolean processExternalEntities)

Indicate whether external XML entities are processed when unmarshalling.

public void
setSchema(Resource schemaResource)

Set the schema resource to use for validation.

public void
setSchemaLanguage(String schemaLanguage)

Set the schema language.

public void
setSchemaResourceResolver(LSResourceResolver schemaResourceResolver)

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

public void
setSchemas(Resource... schemaResources)

Set the schema resources to use for validation.

public void
setSupportDtd(boolean supportDtd)

Indicate whether DTD parsing should be supported.

public void
setSupportJaxbElementClass(boolean supportJaxbElementClass)

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

public void
setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)

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

public void
setUnmarshallerProperties(Map<String, ?>
the properties
properties
)

Set the JAXB Unmarshaller properties.

public void
setValidationEventHandler(ValidationEventHandler validationEventHandler)

Set the JAXB validation event handler.

public boolean
supports(Class<?>
the class that this marshaller is being asked if it can marshal
clazz
)

Implements org.springframework.oxm.Marshaller.supports, org.springframework.oxm.Unmarshaller.supports.

Indicate whether this marshaller can marshal instances of the supplied type.

public boolean
supports(Type
the type that this marshaller is being asked if it can marshal
genericType
)

Implements org.springframework.oxm.GenericMarshaller.supports, org.springframework.oxm.GenericUnmarshaller.supports.

Indicates whether this marshaller can marshal instances of the supplied generic type.

private boolean
supportsInternal(Class<?> clazz, boolean checkForXmlRootElement)

public Object
unmarshal(Source
the source to marshal from
source
)

Implements org.springframework.oxm.Unmarshaller.unmarshal.

Unmarshal the given Source into an object graph.

public Object
unmarshal(Source
the source to marshal from
source
,
MimeContainer
the MIME container to read extracted binary content from
mimeContainer
)

Implements org.springframework.oxm.mime.MimeUnmarshaller.unmarshal.

Unmarshals the given provided Source into an object graph, reading binary attachments from a MimeContainer.

protected Object
unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait