Class XmlSerializer
- All Implemented Interfaces:
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
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static classDefault serializer without namespaces.static classDefault serializer without namespaces, single quotes.static classDefault serializer without namespaces, single quotes, with whitespace.static classDefault serializer, single quotes.static classDefault serializer, single quotes, whitespace added.Nested classes/interfaces inherited from class org.apache.juneau.serializer.Serializer
Serializer.Null -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final booleanprotected final booleanprotected final booleanstatic final XmlSerializerDefault serializer without namespaces.protected static final Namespacestatic final XmlSerializerDefault serializer, all default settings.static final XmlSerializerDefault serializer, single quotes.static final XmlSerializerDefault serializer, single quotes, whitespace added.static final XmlSerializerDefault serializer without namespaces, with single quotes.static final XmlSerializerDefault serializer without namespaces, with single quotes, whitespace added.protected static final Namespaceprotected final booleanFields inherited from class org.apache.juneau.serializer.WriterSerializer
maxIndent, quoteChar, quoteCharOverride, useWhitespaceFields inherited from class org.apache.juneau.serializer.Serializer
accept, addRootType, keepNullProperties, listener, produces, sortCollections, sortMaps, trimEmptyCollections, trimEmptyMaps, trimStringsFields inherited from class org.apache.juneau.BeanContextable
beanContextFields inherited from class org.apache.juneau.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a builder from this context object.static XmlSerializer.Buildercreate()Creates a new builder for this object.Create a session builder based on the properties defined on this context.protected final NamespaceDefault namespace.Default namespaces.Returns a session to use for this context.protected final StringText node delimiter.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 booleanAdd"_type" properties when needed.protected final booleanAdd namespace URLs to the root element.protected final booleanAuto-detect namespace usage.protected final booleanEnable support for XML namespaces.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, toStringMethods 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, serializeToStringMethods inherited from class org.apache.juneau.BeanTraverseContext
getDetectRecursions, getIgnoreRecursions, getInitialDepth, getMaxDepth, isDetectRecursions, isIgnoreRecursionsMethods inherited from class org.apache.juneau.BeanContextable
getBeanContextMethods inherited from class org.apache.juneau.Context
createBuilder, getAnnotationProvider, init, isDebug, toString
-
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
-
addBeanTypesXml
-
addJsonTags
-
addNamespaceUrlsToRoot
-
autoDetectNamespaces
-
enableNamespaces
-
-
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:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
- Overrides:
copyin classWriterSerializer- Returns:
- A new Builder object.
-
createSession
Description copied from class:ContextCreate 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:
createSessionin classWriterSerializer- Returns:
- A new session builder.
-
getSession
Description copied from class:ContextReturns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Overrides:
getSessionin classWriterSerializer- Returns:
- A new session object.
-
getXmlBeanMeta
Description copied from interface:XmlMetaProviderReturns the language-specific metadata on the specified bean.- Specified by:
getXmlBeanMetain interfaceXmlMetaProvider- Parameters:
bm- The bean to return the metadata on.- Returns:
- The metadata.
-
getXmlBeanPropertyMeta
Description copied from interface:XmlMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
getXmlBeanPropertyMetain interfaceXmlMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getXmlClassMeta
Description copied from interface:XmlMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
getXmlClassMetain interfaceXmlMetaProvider- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
getDefaultNamespace
Default namespace.- Returns:
- The default namespace URI for this document.
- See Also:
-
getNamespaces
Default namespaces.- Returns:
- The default list of namespaces associated with this serializer.
Nevernull .
List is unmodifiable. - See Also:
-
getTextNodeDelimiter
Text node delimiter.- Returns:
- The delimiter string to insert between consecutive text nodes.
Nevernull . - See Also:
-
isAddBeanTypes
Add"_type" properties when needed.- Overrides:
isAddBeanTypesin 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:xattributes 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:
-
isEnableNamespaces
Enable support for XML namespaces.- Returns:
false if XML output will not contain any namespaces regardless of any other settings.- See Also:
-
properties
Description copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classWriterSerializer- Returns:
- The properties on this bean as a map for debugging.
-