java.lang.Object
tools.jackson.core.JsonGenerator
tools.jackson.core.base.GeneratorBase
tools.jackson.dataformat.xml.ser.ToXmlGenerator
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,tools.jackson.core.Versioned
public class ToXmlGenerator
extends tools.jackson.core.base.GeneratorBase
JsonGenerator that outputs JAXB-style XML output instead of JSON content.
Operation requires calling code (usually either standard Jackson serializers,
or in some cases (like BeanSerializer) customized ones) to do
additional configuration calls beyond regular JsonGenerator API,
mostly to pass namespace information.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LinkedList<QName>To support proper serialization of arrays it is necessary to keep stack of element names, so that we can "revert" to earlierprotected intBit flag composed of bits that indicate whichXmlWriteFeatures are enabled.protected booleanMarker set wheninitGenerator()has been called or not.protected XmlNameProcessorEscapes names with invalid XML charactersprotected XmlNameProcessor.XmlNameReusable internal value objectprotected booleanMarker flag that indicates whether next name to write implies an attribute (true) or element (false)protected booleanMarker flag used to indicate that the next write of a (property) value should be as CDataprotected booleanMarker flag used to indicate that the next write of a (property) value should be done without using surrounding start/end elements.protected QNameElement or attribute name to use for next output call.protected final XMLStreamWriterprotected final booleanMarker flag set if the underlying stream writer has to emulate Stax2 API: this is problematic if trying to usewriteRaw(java.lang.String)calls.protected tools.jackson.core.util.SimpleStreamWriteContextObject that keeps track of the current contextual state of the generator.protected final XmlPrettyPrinterWe may need to use XML-specific indentation as wellprotected final org.codehaus.stax2.XMLStreamWriter2protected static final StringIf we support optional definition of element names, this is the element name to use...Fields inherited from class tools.jackson.core.base.GeneratorBase
_closed, _ioContext, _objectWriteContext, _streamWriteConstraints, _streamWriteFeatures, DEFAULT_BINARY_WRITE_CAPABILITIES, DEFAULT_TEXTUAL_WRITE_CAPABILITIES, DEFAULT_WRITE_CAPABILITIES, MAX_BIG_DECIMAL_SCALE, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST, WRITE_BINARY, WRITE_BOOLEAN, WRITE_NULL, WRITE_NUMBER, WRITE_RAW, WRITE_STRING -
Constructor Summary
ConstructorsConstructorDescriptionToXmlGenerator(tools.jackson.core.ObjectWriteContext writeCtxt, tools.jackson.core.io.IOContext ioCtxt, int streamWriteFeatures, int xmlFeatures, XMLStreamWriter sw, XmlPrettyPrinter pp, XmlNameProcessor nameProcessor) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected tools.jackson.core.PrettyPrinterfinal voidfinal voidprotected voidprotected void_reportUnimplementedStax2(String missingMethod) Method called in case access to native Stax2 API implementation is required.protected final void_verifyValueWrite(String typeMsg) final voidprotected booleanMethod called to see if unwrapping is required; and if so, clear the flag (so further calls will return 'false' unless state is re-set)configure(XmlWriteFeature f, boolean state) final ObjectvoidfinishWrappedValue(QName wrapperName, QName wrappedName) Method called after a structured collection output has completedvoidflush()Method that allows application direct access to underlying StaxXMLStreamWriter.protected voidbooleanhas(tools.jackson.core.StreamWriteCapability capability) voidMethod called before writing any other output, to optionally output XML declaration.booleaninRoot()final booleanvoidsetNextIsAttribute(boolean isAttribute) voidsetNextIsCData(boolean isCData) voidsetNextIsUnwrapped(boolean isUnwrapped) final voidsetNextName(QName name) final booleansetNextNameIfMissing(QName name) Method that does same assetNextName(javax.xml.namespace.QName), unless a name has already been set.voidstartWrappedValue(QName wrapperName, QName wrappedName) Methdod called when a structured (collection, array, map) is being output.tools.jackson.core.util.JacksonFeatureSet<tools.jackson.core.StreamWriteCapability>final tools.jackson.core.TokenStreamContextintStax2 does not expose buffered content amount, so we can only return-1from heretools.jackson.core.Versionversion()tools.jackson.core.JsonGeneratorwriteBinary(tools.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len) intwriteBinary(tools.jackson.core.Base64Variant b64variant, InputStream data, int dataLength) tools.jackson.core.JsonGeneratorwriteBoolean(boolean value) tools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratorwriteName(tools.jackson.core.SerializableString name) tools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratorwriteNumber(double d) tools.jackson.core.JsonGeneratorwriteNumber(float f) tools.jackson.core.JsonGeneratorwriteNumber(int i) tools.jackson.core.JsonGeneratorwriteNumber(long l) tools.jackson.core.JsonGeneratorwriteNumber(short v) tools.jackson.core.JsonGeneratorwriteNumber(String encodedValue) tools.jackson.core.JsonGeneratorwriteNumber(BigDecimal dec) tools.jackson.core.JsonGeneratorwriteNumber(BigInteger value) tools.jackson.core.JsonGeneratorwritePropertyId(long id) tools.jackson.core.JsonGeneratorwriteRaw(char c) tools.jackson.core.JsonGeneratorwriteRaw(char[] text, int offset, int len) tools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratorwriteRawUTF8String(byte[] text, int offset, int length) tools.jackson.core.JsonGeneratorwriteRawValue(char[] text, int offset, int len) tools.jackson.core.JsonGeneratorwriteRawValue(String text) tools.jackson.core.JsonGeneratorwriteRawValue(String text, int offset, int len) tools.jackson.core.JsonGeneratorwriteRawValue(tools.jackson.core.SerializableString text) tools.jackson.core.JsonGeneratorTrivial helper method called when to add a replicated wrapper nametools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratorwriteStartArray(Object currValue) tools.jackson.core.JsonGeneratortools.jackson.core.JsonGeneratorwriteStartObject(Object currValue) tools.jackson.core.JsonGeneratorwriteString(char[] text, int offset, int len) tools.jackson.core.JsonGeneratorwriteString(String text) tools.jackson.core.JsonGeneratorwriteString(tools.jackson.core.SerializableString text) tools.jackson.core.JsonGeneratorwriteUTF8String(byte[] text, int offset, int length) Methods inherited from class tools.jackson.core.base.GeneratorBase
_asString, _checkRangeBoundsForByteArray, _checkRangeBoundsForCharArray, _checkRangeBoundsForString, _decodeSurrogate, _throwInternal, close, configure, ioContext, isClosed, isEnabled, objectWriteContext, streamWriteConstraints, streamWriteFeatures, writePOJO, writeStartArray, writeStartObject, writeString, writeTreeMethods inherited from class tools.jackson.core.JsonGenerator
_constructWriteException, _constructWriteException, _constructWriteException, _constructWriteException, _copyCurrentContents, _copyCurrentContentsExact, _copyCurrentFloatValue, _copyCurrentFloatValueExact, _copyCurrentIntValue, _copyCurrentStringValue, _reportArgumentError, _reportError, _reportUnsupportedOperation, _reportUnsupportedOperation, _verifyOffsets, _wrapIOFailure, _writeTypePrefixUsingNative, _writeTypePrefixUsingWrapper, canOmitProperties, canWriteObjectId, canWriteTypeId, copyCurrentEvent, copyCurrentEventExact, copyCurrentStructure, copyCurrentStructureExact, getCharacterEscapes, getHighestNonEscapedChar, getSchema, setCharacterEscapes, writeArray, writeArray, writeArray, writeArray, writeArrayPropertyStart, writeBinary, writeBinary, writeBinary, writeBinaryProperty, writeBooleanProperty, writeEmbeddedObject, writeNullProperty, writeNumber, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeObjectId, writeObjectPropertyStart, writeObjectRef, writeOmittedProperty, writePOJOProperty, writeRaw, writeStringProperty, writeTypeId, writeTypePrefix, writeTypeSuffix
-
Field Details
-
DEFAULT_UNKNOWN_ELEMENT
If we support optional definition of element names, this is the element name to use...- See Also:
-
_xmlWriter
protected final org.codehaus.stax2.XMLStreamWriter2 _xmlWriter -
_originalXmlWriter
-
_xmlPrettyPrinter
We may need to use XML-specific indentation as well -
_formatFeatures
protected int _formatFeaturesBit flag composed of bits that indicate whichXmlWriteFeatures are enabled. -
_stax2Emulation
protected final boolean _stax2EmulationMarker flag set if the underlying stream writer has to emulate Stax2 API: this is problematic if trying to usewriteRaw(java.lang.String)calls. -
_streamWriteContext
protected tools.jackson.core.util.SimpleStreamWriteContext _streamWriteContextObject that keeps track of the current contextual state of the generator. -
_nameProcessor
Escapes names with invalid XML characters- Since:
- 2.14
-
_initialized
protected boolean _initializedMarker set wheninitGenerator()has been called or not. -
_nextName
Element or attribute name to use for next output call. Assigned by either code that initiates serialization or bean serializer. -
_nextIsAttribute
protected boolean _nextIsAttributeMarker flag that indicates whether next name to write implies an attribute (true) or element (false) -
_nextIsUnwrapped
protected boolean _nextIsUnwrappedMarker flag used to indicate that the next write of a (property) value should be done without using surrounding start/end elements. Flag is to be cleared once unwrapping has been triggered once. -
_nextIsCData
protected boolean _nextIsCDataMarker flag used to indicate that the next write of a (property) value should be as CData -
_elementNameStack
To support proper serialization of arrays it is necessary to keep stack of element names, so that we can "revert" to earlier -
_nameToEncode
Reusable internal value object
-
-
Constructor Details
-
ToXmlGenerator
public ToXmlGenerator(tools.jackson.core.ObjectWriteContext writeCtxt, tools.jackson.core.io.IOContext ioCtxt, int streamWriteFeatures, int xmlFeatures, XMLStreamWriter sw, XmlPrettyPrinter pp, XmlNameProcessor nameProcessor)
-
-
Method Details
-
initGenerator
public void initGenerator() throws tools.jackson.core.JacksonExceptionMethod called before writing any other output, to optionally output XML declaration.- Throws:
tools.jackson.core.JacksonException
-
version
public tools.jackson.core.Version version()- Specified by:
versionin interfacetools.jackson.core.Versioned- Specified by:
versionin classtools.jackson.core.JsonGenerator
-
streamWriteContext
public final tools.jackson.core.TokenStreamContext streamWriteContext()- Specified by:
streamWriteContextin classtools.jackson.core.JsonGenerator
-
currentValue
- Specified by:
currentValuein classtools.jackson.core.JsonGenerator
-
assignCurrentValue
- Specified by:
assignCurrentValuein classtools.jackson.core.JsonGenerator
-
_constructDefaultPrettyPrinter
protected tools.jackson.core.PrettyPrinter _constructDefaultPrettyPrinter()- Overrides:
_constructDefaultPrettyPrinterin classtools.jackson.core.base.GeneratorBase
-
streamWriteOutputTarget
- Specified by:
streamWriteOutputTargetin classtools.jackson.core.JsonGenerator
-
streamWriteOutputBuffered
public int streamWriteOutputBuffered()Stax2 does not expose buffered content amount, so we can only return-1from here- Specified by:
streamWriteOutputBufferedin classtools.jackson.core.JsonGenerator
-
isEnabled
-
configure
-
has
public boolean has(tools.jackson.core.StreamWriteCapability capability) - Overrides:
hasin classtools.jackson.core.base.GeneratorBase
-
streamWriteCapabilities
public tools.jackson.core.util.JacksonFeatureSet<tools.jackson.core.StreamWriteCapability> streamWriteCapabilities()- Specified by:
streamWriteCapabilitiesin classtools.jackson.core.JsonGenerator
-
inRoot
public boolean inRoot() -
getPrettyPrinter
- Overrides:
getPrettyPrinterin classtools.jackson.core.JsonGenerator
-
getStaxWriter
Method that allows application direct access to underlying StaxXMLStreamWriter. Note that use of writer is discouraged, and may interfere with processing of this writer; however, occasionally it may be necessary.Note: writer instance will always be of type
XMLStreamWriter2(including Typed Access API) so upcasts are safe. -
setNextIsAttribute
public void setNextIsAttribute(boolean isAttribute) -
setNextIsUnwrapped
public void setNextIsUnwrapped(boolean isUnwrapped) -
setNextIsCData
public void setNextIsCData(boolean isCData) -
setNextName
-
setNextNameIfMissing
Method that does same assetNextName(javax.xml.namespace.QName), unless a name has already been set.- Since:
- 2.1.2
-
startWrappedValue
public void startWrappedValue(QName wrapperName, QName wrappedName) throws tools.jackson.core.JacksonException Methdod called when a structured (collection, array, map) is being output.- Parameters:
wrapperName- Element used as wrapper around elements, if any (null if none)wrappedName- Element used around individual content items (can not be null)- Throws:
tools.jackson.core.JacksonException
-
finishWrappedValue
public void finishWrappedValue(QName wrapperName, QName wrappedName) throws tools.jackson.core.JacksonException Method called after a structured collection output has completed- Throws:
tools.jackson.core.JacksonException
-
writeRepeatedPropertyName
public tools.jackson.core.JsonGenerator writeRepeatedPropertyName() throws tools.jackson.core.JacksonExceptionTrivial helper method called when to add a replicated wrapper name- Throws:
tools.jackson.core.JacksonException
-
writeName
public tools.jackson.core.JsonGenerator writeName(tools.jackson.core.SerializableString name) throws tools.jackson.core.JacksonException - Overrides:
writeNamein classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeName
public tools.jackson.core.JsonGenerator writeName(String name) throws tools.jackson.core.JacksonException - Specified by:
writeNamein classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writePropertyId
public tools.jackson.core.JsonGenerator writePropertyId(long id) throws tools.jackson.core.JacksonException - Specified by:
writePropertyIdin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeStartArray
public tools.jackson.core.JsonGenerator writeStartArray() throws tools.jackson.core.JacksonException- Specified by:
writeStartArrayin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeStartArray
public tools.jackson.core.JsonGenerator writeStartArray(Object currValue) throws tools.jackson.core.JacksonException - Specified by:
writeStartArrayin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeEndArray
public tools.jackson.core.JsonGenerator writeEndArray() throws tools.jackson.core.JacksonException- Specified by:
writeEndArrayin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeStartObject
public tools.jackson.core.JsonGenerator writeStartObject() throws tools.jackson.core.JacksonException- Specified by:
writeStartObjectin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeStartObject
public tools.jackson.core.JsonGenerator writeStartObject(Object currValue) throws tools.jackson.core.JacksonException - Specified by:
writeStartObjectin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeEndObject
public tools.jackson.core.JsonGenerator writeEndObject() throws tools.jackson.core.JacksonException- Specified by:
writeEndObjectin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
_handleStartObject
public final void _handleStartObject() throws tools.jackson.core.JacksonException- Throws:
tools.jackson.core.JacksonException
-
_handleEndObject
public final void _handleEndObject() throws tools.jackson.core.JacksonException- Throws:
tools.jackson.core.JacksonException
-
writeString
public tools.jackson.core.JsonGenerator writeString(String text) throws tools.jackson.core.JacksonException - Specified by:
writeStringin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeString
public tools.jackson.core.JsonGenerator writeString(char[] text, int offset, int len) throws tools.jackson.core.JacksonException - Specified by:
writeStringin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeString
public tools.jackson.core.JsonGenerator writeString(tools.jackson.core.SerializableString text) throws tools.jackson.core.JacksonException - Overrides:
writeStringin classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeRawUTF8String
public tools.jackson.core.JsonGenerator writeRawUTF8String(byte[] text, int offset, int length) throws tools.jackson.core.JacksonException - Specified by:
writeRawUTF8Stringin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeUTF8String
public tools.jackson.core.JsonGenerator writeUTF8String(byte[] text, int offset, int length) throws tools.jackson.core.JacksonException - Specified by:
writeUTF8Stringin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeRawValue
public tools.jackson.core.JsonGenerator writeRawValue(String text) throws tools.jackson.core.JacksonException - Overrides:
writeRawValuein classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeRawValue
public tools.jackson.core.JsonGenerator writeRawValue(String text, int offset, int len) throws tools.jackson.core.JacksonException - Overrides:
writeRawValuein classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeRawValue
public tools.jackson.core.JsonGenerator writeRawValue(char[] text, int offset, int len) throws tools.jackson.core.JacksonException - Overrides:
writeRawValuein classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeRawValue
public tools.jackson.core.JsonGenerator writeRawValue(tools.jackson.core.SerializableString text) throws tools.jackson.core.JacksonException - Overrides:
writeRawValuein classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeRaw
public tools.jackson.core.JsonGenerator writeRaw(String text) throws tools.jackson.core.JacksonException - Specified by:
writeRawin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeRaw
public tools.jackson.core.JsonGenerator writeRaw(String text, int offset, int len) throws tools.jackson.core.JacksonException - Specified by:
writeRawin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeRaw
public tools.jackson.core.JsonGenerator writeRaw(char[] text, int offset, int len) throws tools.jackson.core.JacksonException - Specified by:
writeRawin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeRaw
public tools.jackson.core.JsonGenerator writeRaw(char c) throws tools.jackson.core.JacksonException - Specified by:
writeRawin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeBinary
public tools.jackson.core.JsonGenerator writeBinary(tools.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len) throws tools.jackson.core.JacksonException - Specified by:
writeBinaryin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeBinary
public int writeBinary(tools.jackson.core.Base64Variant b64variant, InputStream data, int dataLength) throws tools.jackson.core.JacksonException - Overrides:
writeBinaryin classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
writeBoolean
public tools.jackson.core.JsonGenerator writeBoolean(boolean value) throws tools.jackson.core.JacksonException - Specified by:
writeBooleanin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNull
public tools.jackson.core.JsonGenerator writeNull() throws tools.jackson.core.JacksonException- Specified by:
writeNullin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(short v) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(int i) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(long l) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(double d) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(float f) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(BigDecimal dec) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(BigInteger value) throws tools.jackson.core.JacksonException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonException
-
writeNumber
public tools.jackson.core.JsonGenerator writeNumber(String encodedValue) throws tools.jackson.core.JacksonException, UnsupportedOperationException - Specified by:
writeNumberin classtools.jackson.core.JsonGenerator- Throws:
tools.jackson.core.JacksonExceptionUnsupportedOperationException
-
_verifyValueWrite
- Specified by:
_verifyValueWritein classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
flush
public void flush() throws tools.jackson.core.JacksonException -
_closeInput
protected void _closeInput() throws tools.jackson.core.JacksonException- Specified by:
_closeInputin classtools.jackson.core.base.GeneratorBase- Throws:
tools.jackson.core.JacksonException
-
_releaseBuffers
protected void _releaseBuffers()- Specified by:
_releaseBuffersin classtools.jackson.core.base.GeneratorBase
-
checkNextIsUnwrapped
protected boolean checkNextIsUnwrapped()Method called to see if unwrapping is required; and if so, clear the flag (so further calls will return 'false' unless state is re-set) -
handleMissingName
protected void handleMissingName() -
_reportUnimplementedStax2
protected void _reportUnimplementedStax2(String missingMethod) throws tools.jackson.core.JacksonException Method called in case access to native Stax2 API implementation is required.- Throws:
tools.jackson.core.JacksonException
-