Package org.apache.juneau.xml
Class XmlSerializerSession
- Direct Known Subclasses:
HtmlSerializerSession,SoapXmlSerializerSession,XmlDocSerializerSession
Session object that lives for the duration of a single use of
XmlSerializer.
Notes:
- This class is not thread safe and is typically discarded after one use.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static enumIdentifies what the contents were of a serialized bean. -
Field Summary
Fields inherited from class org.apache.juneau.BeanTraverseSession
indent -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlSerializerSession.Buildercreate(XmlSerializer ctx) Creates a new builder for this object.protected voiddoSerialize(SerializerPipe out, Object o) Serializes a POJO to the specified pipe.protected final voidRecursively searches for the XML namespaces on the specified POJO and adds them to the serializer context object.protected final NamespaceDefault namespace.Default namespaces.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.final XmlWriterConverts the specified output target object to anXmlWriter.protected booleanAdd"_type" properties when needed.protected final booleanAdd JSON type tags.protected final booleanAdd namespace URLs to the root element.protected final booleanAuto-detect namespace usage.protected final booleanEnable support for XML namespaces.protected booleanReturnstrue if we're serializing HTML.protected XmlSerializerSession.ContentResultserializeAnything(XmlWriter out, Object o, ClassMeta<?> eType, String keyName, String elementName, Namespace elementNamespace, boolean addNamespaceUris, XmlFormat format, boolean isMixedOrText, boolean preserveWhitespace, BeanPropertyMeta pMeta) Workhorse method.Methods inherited from class org.apache.juneau.serializer.WriterSerializerSession
create, createPipe, getFileCharset, getMaxIndent, getQuoteChar, getStreamCharset, isUseWhitespace, isWriterSerializer, properties, serialize, serializeToStringMethods inherited from class org.apache.juneau.serializer.SerializerSession
addVarBean, canIgnoreValue, create, createBeanTypeNameProperty, createDefaultVarResolverSession, forEachEntry, forEachEntry, generalize, getBeanTypeName, getExpectedRootType, getJavaMethod, getListener, getListener, getResponseHeaders, getSchema, getUriContext, getUriRelativity, getUriResolution, getUriResolver, getVarResolver, handleThrown, isAddRootType, isKeepNullProperties, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, onBeanGetterException, onError, push2, relativizeUri, resolve, resolveUri, serialize, sort, sort, sort, swap, toList, toString, trimMethods inherited from class org.apache.juneau.BeanTraverseSession
getInitialDepth, getLastLocation, getMaxDepth, getOptionalType, getOptionalValue, getStack, isDetectRecursions, isIgnoreRecursions, isOptional, isRoot, pop, push, setCurrentClass, setCurrentProperty, willExceedDepth, willRecurseMethods inherited from class org.apache.juneau.BeanSession
addWarning, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, create, getAnnotationProvider, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionary, getBeanFieldVisibility, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getLocale, getMediaType, getNamePropertyName, getNotBeanClasses, getNotBeanPackagesNames, getPropertyNamer, getSwaps, getTimeZone, getTimeZoneId, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFindFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnoreMissingSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isSortProperties, isUseEnumNames, isUseInterfaceProxies, isUseJavaBeanIntrospector, newBean, newBean, newBeanMap, newBeanMap, newGenericMap, object, string, toArray, toBeanMap, toBeanMap, toBeanMapMethods inherited from class org.apache.juneau.ContextSession
checkForWarnings, getContext, getSessionProperties, getWarnings, isDebug, toString
-
Constructor Details
-
XmlSerializerSession
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Parameters:
ctx- The context creating this session.
Cannot benull .- Returns:
- A new builder.
-
getXmlBeanMeta
Returns the language-specific metadata on the specified bean.- Parameters:
bm- The bean to return the metadata on.- Returns:
- The metadata.
-
getXmlBeanPropertyMeta
Returns the language-specific metadata on the specified bean property.- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getXmlClassMeta
Returns the language-specific metadata on the specified class.- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
getXmlWriter
Converts the specified output target object to anXmlWriter.- Parameters:
out- The output target object.- Returns:
- The output target object wrapped in an
XmlWriter. - Throws:
IOException- Thrown by underlying stream.
-
doSerialize
Description copied from class:SerializerSessionSerializes a POJO to the specified pipe.This method should NOT close the context object.
The default implementation of this method simply calls
Serializer.doSerialize(SerializerSession,SerializerPipe,Object).- Overrides:
doSerializein classSerializerSession- Parameters:
out- Where to send the output from the serializer.o- The object to serialize.- Throws:
IOException- Thrown by underlying stream.SerializeException- Problem occurred trying to serialize object.
-
findNsfMappings
Recursively searches for the XML namespaces on the specified POJO and adds them to the serializer context object.- Parameters:
o- The POJO to check.- Throws:
SerializeException- Thrown if bean recursion occurred.
-
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 modifiable (namespaces can be added during serialization). - See Also:
-
isAddBeanTypes
Add"_type" properties when needed.- Overrides:
isAddBeanTypesin classSerializerSession- Returns:
true if"_type" properties will be added to beans if their type cannot be inferred through reflection.- See Also:
-
isAddJsonTags
Add JSON type tags.- Returns:
true if plain strings will be wrapped in<string> tags when serialized as root elements.- See Also:
-
isAddNamespaceUrisToRoot
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:
-
isHtmlMode
Returnstrue if we're serializing HTML.The difference in behavior is how empty non-void elements are handled. The XML serializer will produce a collapsed tag, whereas the HTML serializer will produce a start and end tag.
- Returns:
true if we're generating HTML.
-
serializeAnything
protected XmlSerializerSession.ContentResult serializeAnything(XmlWriter out, Object o, ClassMeta<?> eType, String keyName, String elementName, Namespace elementNamespace, boolean addNamespaceUris, XmlFormat format, boolean isMixedOrText, boolean preserveWhitespace, BeanPropertyMeta pMeta) throws SerializeException Workhorse method.- Parameters:
out- The writer to send the output to.o- The object to serialize.eType- The expected type if this is a bean property value being serialized.keyName- The property name or map key name.elementName- The root element name.elementNamespace- The namespace of the element.addNamespaceUris- Flag indicating that namespace URIs need to be added.format- The format to serialize the output to.isMixedOrText- We're serializing mixed content, so don't use whitespace.preserveWhitespace-true if we're serializingXmlFormat.MIXED_PWSorXmlFormat.TEXT_PWS.pMeta- The bean property metadata if this is a bean property being serialized.- Returns:
- The same writer passed in so that calls to the writer can be chained.
- Throws:
SerializeException- General serialization error occurred.
-