Package org.apache.juneau.marshall.xml
Class XmlSerializerSession
java.lang.Object
org.apache.juneau.marshall.ContextSession
org.apache.juneau.marshall.MarshallingSession
org.apache.juneau.marshall.MarshallingTraverseSession
org.apache.juneau.marshall.serializer.SerializerSession
org.apache.juneau.marshall.serializer.WriterSerializerSession
org.apache.juneau.marshall.xml.XmlSerializerSession
- All Implemented Interfaces:
BeanSession,ConverterSession,RecordWritable
- 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.static final classConcrete default builder leaf for the non-subclassedcreate()path (CRTP terminal). -
Field Summary
Fields inherited from class org.apache.juneau.marshall.MarshallingTraverseSession
indentFields inherited from class org.apache.juneau.marshall.MarshallingSession
NAME_PROPERTY_NAME -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedXmlSerializerSession(XmlSerializerSession.Builder<?> builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlSerializerSession.Builder<?>create(XmlSerializer ctx) Creates a new builder for this object.protected voiddoWrite(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 XmlWriter<?>Converts the specified output target object to anXmlWriter.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.booleanThe XML record writer is buffered/RecordAdapter-backed, not O(1) streaming.protected XmlSerializerSession.ContentResultwriteAnything(XmlWriter<?> out, Object o, ClassMeta<?> eType, String keyName, String elementName, Namespace elementNamespace, boolean addNamespaceUris, XmlFormat format, boolean isMixedOrText, boolean preserveWhitespace, BeanPropertyMeta pMeta) Workhorse method.writeRecords(Object output) Opens a whole-value push generator targeting XML output, bound to this live session.Methods inherited from class org.apache.juneau.marshall.serializer.WriterSerializerSession
create, createPipe, getMaxIndent, getQuoteChar, getStreamCharset, isUseWhitespace, isWriterSerializer, properties, write, writeToStringMethods inherited from class org.apache.juneau.marshall.serializer.SerializerSession
addVarBean, canIgnoreValue, canIgnoreValue, create, createBeanTypeNameProperty, createDefaultVarResolverSession, forEachEntry, forEachEntry, forEachStreamableEntry, generalize, getBeanTypeName, getCalendarFormat, getDateFormat, getDurationFormat, getExpectedRootType, getJavaMethod, getListener, getListener, getLocaleFormat, getPeriodFormat, getResponseHeaders, getSchema, getTemporalFormat, getTimeZoneFormat, getUriContext, getUriRelativity, getUriResolution, getUriResolver, getVarResolver, handleThrown, isAddRootType, isKeepNullProperties, isNonDefault, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, onBeanGetterException, onError, push2, relativizeUri, resolve, resolveUri, sort, sort, sort, swap, toList, toListFromStreamable, toString, trim, unwrapSupplier, write, writeCalendar, writeDate, writeDuration, writePeriod, writeTemporalMethods inherited from class org.apache.juneau.marshall.MarshallingTraverseSession
getInitialDepth, getLastLocation, getMaxDepth, getOptionalType, getOptionalValue, getStack, isDetectRecursions, isIgnoreRecursions, isOptional, isRoot, pop, push, setCurrentClass, setCurrentProperty, willExceedDepth, willRecurseMethods inherited from class org.apache.juneau.marshall.MarshallingSession
addWarning, convertToMemberType, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, convertToType, create, get, getActiveView, getAnnotationProvider, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionary, getBeanFieldVisibility, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassLoader, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getLocale, getMarshallingContext, getMediaType, getNotBeanClasses, getNotBeanPackagesNames, getPropertyNamer, getSwaps, getTimeZone, getTimeZoneId, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFindFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnoreMissingSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isPropertyInActiveView, isRecordComponentOrder, isUnsortedProperties, isUseInterfaceProxies, isUseJavaBeanIntrospector, isValidateSchema, newBean, newBean, newBeanMap, newBeanMap, newGenericList, newGenericMap, newGenericMap, object, parseToList, parseToMap, string, toArray, toBeanMap, toBeanMap, toBeanMapMethods inherited from class org.apache.juneau.marshall.ContextSession
checkForWarnings, getContext, getSessionProperties, getWarnings, isDebug, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.conversion.ConverterSession
get
-
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.
Must not benull .- Returns:
- The output target object wrapped in an
XmlWriter.
-
doWrite
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.doWrite(SerializerSession,SerializerPipe,Object).- Overrides:
doWritein 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.
-
writeRecords
Opens a whole-value push generator targeting XML output, bound to this live session.Because XML's wire format (attributes, namespaces, mixed content) is non-trivial to expose as a fine-grained token writer, this implementation supports only the cursor-level POJO bridge —
write(Object)delegates toSerializerSession.write(Object, Object).- Specified by:
writeRecordsin interfaceRecordWritable- Parameters:
output- The output.- Returns:
- A new
RecordWriter. - Throws:
IOException- If a problem occurred opening the underlying output.
-
isRecordStreaming
The XML record writer is buffered/RecordAdapter-backed, not O(1) streaming.- Specified by:
isRecordStreamingin interfaceRecordWritable- Returns:
- Always
false .
-
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
Description copied from class:SerializerSessionAdd"_type" properties when needed.- Overrides:
isAddBeanTypesin classSerializerSession- Returns:
true if"_type" properties 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.
-
writeAnything
protected XmlSerializerSession.ContentResult writeAnything(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.
Must not benull .o- The object to serialize.
Can benull (written as the XML null representation, e.g.type='null' ).eType- The expected type if this is a bean property value being serialized.
Can benull (treated as the genericObjecttype).keyName- The property name or map key name.
Can benull (the element is written without a separate property/key name).elementName- The root element name.
Can benull (falls back to the bean dictionary name, thenkeyName , then the JSON type name).elementNamespace- The namespace of the element.
Can benull (resolved from the serialized type's, then the actual type's, then the session's default namespace).addNamespaceUris- Flag indicating that namespace URIs need to be added.format- The format to serialize the output to.
Must not benull .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.
Can benull (no bean-property-level URI/child-name/namespace metadata is applied).- Returns:
- The same writer passed in so that calls to the writer can be chained.
- Throws:
SerializeException- General serialization error occurred.
-