Class XmlSerializer
- All Implemented Interfaces:
AnnotationProvider
,XmlMetaProvider
- Direct Known Subclasses:
HtmlSerializer
,SoapXmlSerializer
,XmlDocSerializer
,XmlSerializer.Ns
,XmlSerializer.NsSq
,XmlSerializer.NsSqReadable
,XmlSerializer.Sq
,XmlSerializer.SqReadable
Media types
Handles
Produces
Description
See the JsonSerializer
class for details on how Java models map to JSON.
For example, the following JSON...
{
name:
...maps to the following XML using the default serializer...
An additional "add-json-properties" mode is also provided to prevent loss of JSON data types...
This serializer provides several serialization options.
Typically, one of the predefined
If an attribute name contains any non-valid XML element characters, they will be escaped using standard
_x####_
notation.
Behavior-specific subclasses
The following direct subclasses are provided for convenience:
XmlSerializer.Sq
- Default serializer, single quotes.XmlSerializer.SqReadable
- Default serializer, single quotes, whitespace added.
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class.static class
Default serializer without namespaces.static class
Default serializer without namespaces, single quotes.static class
Default serializer without namespaces, single quotes, with whitespace.static class
Default serializer, single quotes.static class
Default serializer, single quotes, whitespace added.Nested classes/interfaces inherited from class org.apache.juneau.serializer.Serializer
Serializer.Null
-
Field Summary
Modifier and TypeFieldDescriptionstatic final XmlSerializer
Default serializer without namespaces.protected static final Namespace
static final XmlSerializer
Default serializer, all default settings.static final XmlSerializer
Default serializer, single quotes.static final XmlSerializer
Default serializer, single quotes, whitespace added.static final XmlSerializer
Default serializer without namespaces, with single quotes.static final XmlSerializer
Default serializer without namespaces, with single quotes, whitespace added.protected static final Namespace
Fields inherited from class org.apache.juneau.Context
CONTEXT_APPLY_FILTER
Fields inherited from interface org.apache.juneau.AnnotationProvider
DISABLE_ANNOTATION_CACHING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a builder from this context object.static XmlSerializer.Builder
create()
Creates a new builder for this object.Create a session builder based on the properties defined on this context.protected final Namespace
Default namespace.protected final Namespace[]
Default namespaces.Returns a session to use for this context.getXmlBeanMeta
(BeanMeta<?> bm) Returns the language-specific metadata on the specified bean.Returns the language-specific metadata on the specified bean property.getXmlClassMeta
(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.protected boolean
Add"_type" properties when needed.protected final boolean
Add namespace URLs to the root element.protected final boolean
Auto-detect namespace usage.protected final boolean
Enable support for XML namespaces.protected JsonMap
Returns the properties on this bean as a map for debugging.Methods inherited from class org.apache.juneau.serializer.WriterSerializer
getFileCharset, getMaxIndent, getQuoteChar, getStreamCharset, isUseWhitespace, isWriterSerializer, println, quoteChar, serialize, toString
Methods inherited from class org.apache.juneau.serializer.Serializer
createSerializerBuilder, doSerialize, forEachAcceptMediaType, getListener, getMediaTypeRanges, getPrimaryMediaType, getResponseContentType, getResponseHeaders, getUriContext, getUriRelativity, getUriResolution, isAddRootType, isKeepNullProperties, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, serialize, serializeToString
Methods inherited from class org.apache.juneau.BeanTraverseContext
getInitialDepth, getMaxDepth, isDetectRecursions, isIgnoreRecursions
Methods inherited from class org.apache.juneau.BeanContextable
getBeanContext
Methods inherited from class org.apache.juneau.Context
createBuilder, firstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, init, isDebug, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.juneau.AnnotationProvider
firstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation
-
Field Details
-
DEFAULT
Default serializer without namespaces. -
DEFAULT_SQ
Default serializer without namespaces, with single quotes. -
DEFAULT_SQ_READABLE
Default serializer without namespaces, with single quotes, whitespace added. -
DEFAULT_NS
Default serializer, all default settings. -
DEFAULT_NS_SQ
Default serializer, single quotes. -
DEFAULT_NS_SQ_READABLE
Default serializer, single quotes, whitespace added. -
DEFAULT_JUNEAU_NAMESPACE
-
DEFAULT_XS_NAMESPACE
-
-
Constructor Details
-
XmlSerializer
Constructor.- Parameters:
builder
- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
copy
Description copied from class:Context
Creates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
- Overrides:
copy
in classWriterSerializer
- Returns:
- A new Builder object.
-
createSession
Description copied from class:Context
Create a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use
Context.getSession()
directly.- Overrides:
createSession
in classWriterSerializer
- Returns:
- A new session builder.
-
getSession
Description copied from class:Context
Returns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Overrides:
getSession
in classWriterSerializer
- Returns:
- A new session object.
-
getXmlClassMeta
Description copied from interface:XmlMetaProvider
Returns the language-specific metadata on the specified class.- Specified by:
getXmlClassMeta
in interfaceXmlMetaProvider
- Parameters:
cm
- The class to return the metadata on.- Returns:
- The metadata.
-
getXmlBeanMeta
Description copied from interface:XmlMetaProvider
Returns the language-specific metadata on the specified bean.- Specified by:
getXmlBeanMeta
in interfaceXmlMetaProvider
- Parameters:
bm
- The bean to return the metadata on.- Returns:
- The metadata.
-
getXmlBeanPropertyMeta
Description copied from interface:XmlMetaProvider
Returns the language-specific metadata on the specified bean property.- Specified by:
getXmlBeanPropertyMeta
in interfaceXmlMetaProvider
- Parameters:
bpm
- The bean property to return the metadata on.- Returns:
- The metadata.
-
isAddBeanTypes
Add"_type" properties when needed.- Overrides:
isAddBeanTypes
in classSerializer
- Returns:
true if"_type" properties will be added to beans if their type cannot be inferred through reflection.- See Also:
-
isAddNamespaceUrlsToRoot
Add namespace URLs to the root element.- Returns:
true ifxmlns:x
attributes are added to the root element for the default and all mapped namespaces.- See Also:
-
isAutoDetectNamespaces
Auto-detect namespace usage.- Returns:
true if namespace usage is detected before serialization.- See Also:
-
getDefaultNamespace
Default namespace.- Returns:
- The default namespace URI for this document.
- See Also:
-
isEnableNamespaces
Enable support for XML namespaces.- Returns:
false if XML output will not contain any namespaces regardless of any other settings.- See Also:
-
getNamespaces
Default namespaces.- Returns:
- The default list of namespaces associated with this serializer.
- See Also:
-
properties
Description copied from class:Context
Returns the properties on this bean as a map for debugging.- Overrides:
properties
in classWriterSerializer
- Returns:
- The properties on this bean as a map for debugging.
-