Class ToXmlGenerator
- java.lang.Object
-
- com.fasterxml.jackson.core.JsonGenerator
-
- com.fasterxml.jackson.core.base.GeneratorBase
-
- com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator
-
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
,java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public final class ToXmlGenerator extends com.fasterxml.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 (likeBeanSerializer
) customised ones) to do additional configuration calls beyond regularJsonGenerator
API, mostly to pass namespace information.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ToXmlGenerator.Feature
Enumeration that defines all togglable extra XML-specific features
-
Field Summary
Fields Modifier and Type Field Description protected java.util.LinkedList<javax.xml.namespace.QName>
_elementNameStack
To support proper serialization of arrays it is necessary to keep stack of element names, so that we can "revert" to earlierprotected int
_formatFeatures
Bit flag composed of bits that indicate whichToXmlGenerator.Feature
s are enabled.protected boolean
_initialized
Marker set wheninitGenerator()
has been called or not.protected com.fasterxml.jackson.core.io.IOContext
_ioContext
protected boolean
_nextIsAttribute
Marker flag that indicates whether next name to write implies an attribute (true) or element (false)protected boolean
_nextIsCData
Marker flag used to indicate that the next write of a (property) value should be as CDataprotected boolean
_nextIsUnwrapped
Marker flag used to indicate that the next write of a (property) value should be done without using surrounding start/end elements.protected javax.xml.namespace.QName
_nextName
Element or attribute name to use for next output call.protected javax.xml.stream.XMLStreamWriter
_originalXmlWriter
protected boolean
_stax2Emulation
Marker flag set if the underlying stream writer has to emulate Stax2 API: this is problematic if trying to usewriteRaw(java.lang.String)
calls.protected XmlPrettyPrinter
_xmlPrettyPrinter
We may need to use XML-specific indentation as wellprotected org.codehaus.stax2.XMLStreamWriter2
_xmlWriter
protected static java.lang.String
DEFAULT_UNKNOWN_ELEMENT
If we support optional definition of element names, this is the element name to use...-
Fields inherited from class com.fasterxml.jackson.core.base.GeneratorBase
_cfgNumbersAsStrings, _closed, _features, _objectCodec, _writeContext, DERIVED_FEATURES_MASK, 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
Constructors Constructor Description ToXmlGenerator(com.fasterxml.jackson.core.io.IOContext ctxt, int stdFeatures, int xmlFeatures, com.fasterxml.jackson.core.ObjectCodec codec, javax.xml.stream.XMLStreamWriter sw)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.fasterxml.jackson.core.PrettyPrinter
_constructDefaultPrettyPrinter()
void
_handleEndObject()
void
_handleStartObject()
protected void
_releaseBuffers()
protected void
_reportUnimplementedStax2(java.lang.String missingMethod)
Method called in case access to native Stax2 API implementation is required.protected void
_verifyValueWrite(java.lang.String typeMsg)
boolean
canWriteFormattedNumbers()
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)void
close()
ToXmlGenerator
configure(ToXmlGenerator.Feature f, boolean state)
ToXmlGenerator
disable(ToXmlGenerator.Feature f)
ToXmlGenerator
enable(ToXmlGenerator.Feature f)
void
finishWrappedValue(javax.xml.namespace.QName wrapperName, javax.xml.namespace.QName wrappedName)
Method called after a structured collection output has completedvoid
flush()
int
getFormatFeatures()
int
getOutputBuffered()
Stax2 does not expose buffered content amount, so we can only return-1
from herejava.lang.Object
getOutputTarget()
javax.xml.stream.XMLStreamWriter
getStaxWriter()
Method that allows application direct access to underlying StaxXMLStreamWriter
.protected void
handleMissingName()
void
initGenerator()
Method called before writing any other output, to optionally output XML declaration.boolean
inRoot()
boolean
isEnabled(ToXmlGenerator.Feature f)
com.fasterxml.jackson.core.JsonGenerator
overrideFormatFeatures(int values, int mask)
void
setNextIsAttribute(boolean isAttribute)
void
setNextIsCData(boolean isCData)
void
setNextIsUnwrapped(boolean isUnwrapped)
void
setNextName(javax.xml.namespace.QName name)
boolean
setNextNameIfMissing(javax.xml.namespace.QName name)
Method that does same assetNextName(javax.xml.namespace.QName)
, unless a name has already been set.com.fasterxml.jackson.core.JsonGenerator
setPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp)
void
startWrappedValue(javax.xml.namespace.QName wrapperName, javax.xml.namespace.QName wrappedName)
Methdod called when a structured (collection, array, map) is being output.void
writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len)
int
writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant, java.io.InputStream data, int dataLength)
void
writeBoolean(boolean value)
void
writeEndArray()
void
writeEndObject()
void
writeFieldName(com.fasterxml.jackson.core.SerializableString name)
void
writeFieldName(java.lang.String name)
void
writeNull()
void
writeNumber(double d)
void
writeNumber(float f)
void
writeNumber(int i)
void
writeNumber(long l)
void
writeNumber(java.lang.String encodedValue)
void
writeNumber(java.math.BigDecimal dec)
void
writeNumber(java.math.BigInteger value)
void
writeRaw(char c)
void
writeRaw(char[] text, int offset, int len)
void
writeRaw(java.lang.String text)
void
writeRaw(java.lang.String text, int offset, int len)
void
writeRawUTF8String(byte[] text, int offset, int length)
void
writeRawValue(char[] text, int offset, int len)
void
writeRawValue(com.fasterxml.jackson.core.SerializableString text)
void
writeRawValue(java.lang.String text)
void
writeRawValue(java.lang.String text, int offset, int len)
void
writeRepeatedFieldName()
Trivial helper method called when to add a replicated wrapper namevoid
writeStartArray()
void
writeStartObject()
void
writeString(char[] text, int offset, int len)
void
writeString(com.fasterxml.jackson.core.SerializableString text)
void
writeString(java.lang.String text)
void
writeStringField(java.lang.String fieldName, java.lang.String value)
void
writeUTF8String(byte[] text, int offset, int length)
-
Methods inherited from class com.fasterxml.jackson.core.base.GeneratorBase
_asString, _checkStdFeatureChanges, _decodeSurrogate, disable, enable, getCodec, getCurrentValue, getFeatureMask, getOutputContext, isClosed, isEnabled, overrideStdFeatures, setCodec, setCurrentValue, setFeatureMask, useDefaultPrettyPrinter, version, writeObject, writeStartObject, writeTree
-
Methods inherited from class com.fasterxml.jackson.core.JsonGenerator
_copyCurrentContents, _reportError, _reportUnsupportedOperation, _throwInternal, _verifyOffsets, _writeSimpleObject, canOmitFields, canUseSchema, canWriteBinaryNatively, canWriteObjectId, canWriteTypeId, configure, copyCurrentEvent, copyCurrentStructure, getCharacterEscapes, getHighestEscapedChar, getPrettyPrinter, getSchema, isEnabled, setCharacterEscapes, setHighestNonEscapedChar, setRootValueSeparator, setSchema, writeArray, writeArray, writeArray, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeEmbeddedObject, writeFieldId, writeNullField, writeNumber, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeObjectId, writeObjectRef, writeOmittedField, writeRaw, writeStartArray, writeStartArray, writeStartArray, writeStartObject, writeString, writeTypeId, writeTypePrefix, writeTypeSuffix
-
-
-
-
Field Detail
-
DEFAULT_UNKNOWN_ELEMENT
protected static final java.lang.String DEFAULT_UNKNOWN_ELEMENT
If we support optional definition of element names, this is the element name to use...- See Also:
- Constant Field Values
-
_xmlWriter
protected final org.codehaus.stax2.XMLStreamWriter2 _xmlWriter
-
_originalXmlWriter
protected final javax.xml.stream.XMLStreamWriter _originalXmlWriter
-
_stax2Emulation
protected final boolean _stax2Emulation
Marker flag set if the underlying stream writer has to emulate Stax2 API: this is problematic if trying to usewriteRaw(java.lang.String)
calls.
-
_ioContext
protected final com.fasterxml.jackson.core.io.IOContext _ioContext
-
_formatFeatures
protected int _formatFeatures
Bit flag composed of bits that indicate whichToXmlGenerator.Feature
s are enabled.
-
_xmlPrettyPrinter
protected XmlPrettyPrinter _xmlPrettyPrinter
We may need to use XML-specific indentation as well
-
_initialized
protected boolean _initialized
Marker set wheninitGenerator()
has been called or not.- Since:
- 2.2
-
_nextName
protected javax.xml.namespace.QName _nextName
Element or attribute name to use for next output call. Assigned by either code that initiates serialization or bean serializer.
-
_nextIsAttribute
protected boolean _nextIsAttribute
Marker flag that indicates whether next name to write implies an attribute (true) or element (false)
-
_nextIsUnwrapped
protected boolean _nextIsUnwrapped
Marker 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 _nextIsCData
Marker flag used to indicate that the next write of a (property) value should be as CData
-
_elementNameStack
protected java.util.LinkedList<javax.xml.namespace.QName> _elementNameStack
To support proper serialization of arrays it is necessary to keep stack of element names, so that we can "revert" to earlier
-
-
Method Detail
-
initGenerator
public void initGenerator() throws java.io.IOException
Method called before writing any other output, to optionally output XML declaration.- Throws:
java.io.IOException
-
_constructDefaultPrettyPrinter
protected com.fasterxml.jackson.core.PrettyPrinter _constructDefaultPrettyPrinter()
- Overrides:
_constructDefaultPrettyPrinter
in classcom.fasterxml.jackson.core.base.GeneratorBase
-
setPrettyPrinter
public com.fasterxml.jackson.core.JsonGenerator setPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp)
- Overrides:
setPrettyPrinter
in classcom.fasterxml.jackson.core.JsonGenerator
-
getOutputTarget
public java.lang.Object getOutputTarget()
- Overrides:
getOutputTarget
in classcom.fasterxml.jackson.core.JsonGenerator
-
getOutputBuffered
public int getOutputBuffered()
Stax2 does not expose buffered content amount, so we can only return-1
from here- Overrides:
getOutputBuffered
in classcom.fasterxml.jackson.core.JsonGenerator
-
getFormatFeatures
public int getFormatFeatures()
- Overrides:
getFormatFeatures
in classcom.fasterxml.jackson.core.JsonGenerator
-
overrideFormatFeatures
public com.fasterxml.jackson.core.JsonGenerator overrideFormatFeatures(int values, int mask)
- Overrides:
overrideFormatFeatures
in classcom.fasterxml.jackson.core.JsonGenerator
-
enable
public ToXmlGenerator enable(ToXmlGenerator.Feature f)
-
disable
public ToXmlGenerator disable(ToXmlGenerator.Feature f)
-
isEnabled
public final boolean isEnabled(ToXmlGenerator.Feature f)
-
configure
public ToXmlGenerator configure(ToXmlGenerator.Feature f, boolean state)
-
canWriteFormattedNumbers
public boolean canWriteFormattedNumbers()
- Overrides:
canWriteFormattedNumbers
in classcom.fasterxml.jackson.core.JsonGenerator
-
inRoot
public boolean inRoot()
-
getStaxWriter
public javax.xml.stream.XMLStreamWriter 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
public final void setNextName(javax.xml.namespace.QName name)
-
setNextNameIfMissing
public final boolean setNextNameIfMissing(javax.xml.namespace.QName name)
Method that does same assetNextName(javax.xml.namespace.QName)
, unless a name has already been set.- Since:
- 2.1.2
-
startWrappedValue
public void startWrappedValue(javax.xml.namespace.QName wrapperName, javax.xml.namespace.QName wrappedName) throws java.io.IOException
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:
java.io.IOException
-
finishWrappedValue
public void finishWrappedValue(javax.xml.namespace.QName wrapperName, javax.xml.namespace.QName wrappedName) throws java.io.IOException
Method called after a structured collection output has completed- Throws:
java.io.IOException
-
writeRepeatedFieldName
public void writeRepeatedFieldName() throws java.io.IOException
Trivial helper method called when to add a replicated wrapper name- Throws:
java.io.IOException
- Since:
- 2.2
-
writeFieldName
public final void writeFieldName(java.lang.String name) throws java.io.IOException
- Specified by:
writeFieldName
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeStringField
public final void writeStringField(java.lang.String fieldName, java.lang.String value) throws java.io.IOException
- Overrides:
writeStringField
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeStartArray
public final void writeStartArray() throws java.io.IOException
- Specified by:
writeStartArray
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeEndArray
public final void writeEndArray() throws java.io.IOException
- Specified by:
writeEndArray
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeStartObject
public final void writeStartObject() throws java.io.IOException
- Specified by:
writeStartObject
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeEndObject
public final void writeEndObject() throws java.io.IOException
- Specified by:
writeEndObject
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
_handleStartObject
public final void _handleStartObject() throws java.io.IOException
- Throws:
java.io.IOException
-
_handleEndObject
public final void _handleEndObject() throws java.io.IOException
- Throws:
java.io.IOException
-
writeFieldName
public void writeFieldName(com.fasterxml.jackson.core.SerializableString name) throws java.io.IOException
- Overrides:
writeFieldName
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeString
public void writeString(java.lang.String text) throws java.io.IOException
- Specified by:
writeString
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeString
public void writeString(char[] text, int offset, int len) throws java.io.IOException
- Specified by:
writeString
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeString
public void writeString(com.fasterxml.jackson.core.SerializableString text) throws java.io.IOException
- Overrides:
writeString
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeRawUTF8String
public void writeRawUTF8String(byte[] text, int offset, int length) throws java.io.IOException
- Specified by:
writeRawUTF8String
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeUTF8String
public void writeUTF8String(byte[] text, int offset, int length) throws java.io.IOException
- Specified by:
writeUTF8String
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeRawValue
public void writeRawValue(java.lang.String text) throws java.io.IOException
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeRawValue
public void writeRawValue(java.lang.String text, int offset, int len) throws java.io.IOException
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeRawValue
public void writeRawValue(char[] text, int offset, int len) throws java.io.IOException
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeRawValue
public void writeRawValue(com.fasterxml.jackson.core.SerializableString text) throws java.io.IOException
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeRaw
public void writeRaw(java.lang.String text) throws java.io.IOException
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeRaw
public void writeRaw(java.lang.String text, int offset, int len) throws java.io.IOException
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeRaw
public void writeRaw(char[] text, int offset, int len) throws java.io.IOException
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeRaw
public void writeRaw(char c) throws java.io.IOException
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeBinary
public void writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len) throws java.io.IOException
- Specified by:
writeBinary
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeBinary
public int writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant, java.io.InputStream data, int dataLength) throws java.io.IOException
- Overrides:
writeBinary
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean value) throws java.io.IOException
- Specified by:
writeBoolean
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNull
public void writeNull() throws java.io.IOException
- Specified by:
writeNull
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(int i) throws java.io.IOException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(long l) throws java.io.IOException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(double d) throws java.io.IOException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(float f) throws java.io.IOException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(java.math.BigDecimal dec) throws java.io.IOException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(java.math.BigInteger value) throws java.io.IOException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
-
writeNumber
public void writeNumber(java.lang.String encodedValue) throws java.io.IOException, java.lang.UnsupportedOperationException
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
java.io.IOException
java.lang.UnsupportedOperationException
-
_verifyValueWrite
protected final void _verifyValueWrite(java.lang.String typeMsg) throws java.io.IOException
- Specified by:
_verifyValueWrite
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
java.io.IOException
-
_releaseBuffers
protected void _releaseBuffers()
- Specified by:
_releaseBuffers
in classcom.fasterxml.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(java.lang.String missingMethod) throws java.io.IOException
Method called in case access to native Stax2 API implementation is required.- Throws:
java.io.IOException
-
-