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 (like BeanSerializer
) customised ones) to do
additional configuration calls beyond regular JsonGenerator
API,
mostly to pass namespace information.Modifier and Type | Class and Description |
---|---|
static class |
ToXmlGenerator.Feature
Enumeration that defines all togglable extra XML-specific features
|
Modifier and Type | Field and Description |
---|---|
protected LinkedList<QName> |
_elementNameStack
To support proper serialization of arrays it is necessary to keep
stack of element names, so that we can "revert" to earlier
|
protected int |
_formatFeatures
Bit flag composed of bits that indicate which
ToXmlGenerator.Feature s
are enabled. |
protected boolean |
_initialized
Marker set when
initGenerator() 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 CData
|
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.
|
protected QName |
_nextName
Element or attribute name to use for next output call.
|
protected XMLStreamWriter |
_originalXmlWriter |
protected boolean |
_stax2Emulation
Marker flag set if the underlying stream writer has to emulate
Stax2 API: this is problematic if trying to use
writeRaw(java.lang.String) calls. |
protected XmlPrettyPrinter |
_xmlPrettyPrinter
We may need to use XML-specific indentation as well
|
protected org.codehaus.stax2.XMLStreamWriter2 |
_xmlWriter |
protected static String |
DEFAULT_UNKNOWN_ELEMENT
If we support optional definition of element names, this is the element
name to use...
|
_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 and Description |
---|
ToXmlGenerator(com.fasterxml.jackson.core.io.IOContext ctxt,
int stdFeatures,
int xmlFeatures,
com.fasterxml.jackson.core.ObjectCodec codec,
XMLStreamWriter sw) |
Modifier and Type | Method and Description |
---|---|
protected com.fasterxml.jackson.core.PrettyPrinter |
_constructDefaultPrettyPrinter() |
void |
_handleEndObject() |
void |
_handleStartObject() |
protected void |
_releaseBuffers() |
protected void |
_reportUnimplementedStax2(String missingMethod)
Method called in case access to native Stax2 API implementation is required.
|
protected void |
_verifyValueWrite(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(QName wrapperName,
QName wrappedName)
Method called after a structured collection output has completed
|
void |
flush() |
int |
getFormatFeatures() |
int |
getOutputBuffered()
Stax2 does not expose buffered content amount, so we can only return
-1 from here |
Object |
getOutputTarget() |
XMLStreamWriter |
getStaxWriter()
Method that allows application direct access to underlying
Stax
XMLStreamWriter . |
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(QName name) |
boolean |
setNextNameIfMissing(QName name)
Method that does same as
setNextName(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(QName wrapperName,
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) |
void |
writeBoolean(boolean value) |
void |
writeEndArray() |
void |
writeEndObject() |
void |
writeFieldName(com.fasterxml.jackson.core.SerializableString name) |
void |
writeFieldName(String name) |
void |
writeNull() |
void |
writeNumber(BigDecimal dec) |
void |
writeNumber(BigInteger value) |
void |
writeNumber(double d) |
void |
writeNumber(float f) |
void |
writeNumber(int i) |
void |
writeNumber(long l) |
void |
writeNumber(String encodedValue) |
void |
writeRaw(char c) |
void |
writeRaw(char[] text,
int offset,
int len) |
void |
writeRaw(String text) |
void |
writeRaw(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(String text) |
void |
writeRawValue(String text,
int offset,
int len) |
void |
writeRepeatedFieldName()
Trivial helper method called when to add a replicated wrapper name
|
void |
writeStartArray() |
void |
writeStartObject() |
void |
writeString(char[] text,
int offset,
int len) |
void |
writeString(com.fasterxml.jackson.core.SerializableString text) |
void |
writeString(String text) |
void |
writeStringField(String fieldName,
String value) |
void |
writeUTF8String(byte[] text,
int offset,
int length) |
_asString, _checkStdFeatureChanges, _decodeSurrogate, disable, enable, getCodec, getCurrentValue, getFeatureMask, getOutputContext, isClosed, isEnabled, overrideStdFeatures, setCodec, setCurrentValue, setFeatureMask, useDefaultPrettyPrinter, version, writeBinary, writeObject, writeStartObject, writeTree
_reportError, _reportUnsupportedOperation, _throwInternal, _verifyOffsets, _writeSimpleObject, canOmitFields, canUseSchema, canWriteBinaryNatively, canWriteObjectId, canWriteTypeId, configure, copyCurrentEvent, copyCurrentStructure, getCharacterEscapes, getHighestEscapedChar, getPrettyPrinter, getSchema, 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, writeString, writeTypeId, writeTypePrefix, writeTypeSuffix
protected static final String DEFAULT_UNKNOWN_ELEMENT
protected final org.codehaus.stax2.XMLStreamWriter2 _xmlWriter
protected final XMLStreamWriter _originalXmlWriter
protected final boolean _stax2Emulation
writeRaw(java.lang.String)
calls.protected final com.fasterxml.jackson.core.io.IOContext _ioContext
protected int _formatFeatures
ToXmlGenerator.Feature
s
are enabled.protected XmlPrettyPrinter _xmlPrettyPrinter
protected boolean _initialized
initGenerator()
has been called or not.protected QName _nextName
protected boolean _nextIsAttribute
protected boolean _nextIsUnwrapped
protected boolean _nextIsCData
protected LinkedList<QName> _elementNameStack
public ToXmlGenerator(com.fasterxml.jackson.core.io.IOContext ctxt, int stdFeatures, int xmlFeatures, com.fasterxml.jackson.core.ObjectCodec codec, XMLStreamWriter sw)
public void initGenerator() throws IOException
IOException
protected com.fasterxml.jackson.core.PrettyPrinter _constructDefaultPrettyPrinter()
_constructDefaultPrettyPrinter
in class com.fasterxml.jackson.core.base.GeneratorBase
public com.fasterxml.jackson.core.JsonGenerator setPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp)
setPrettyPrinter
in class com.fasterxml.jackson.core.JsonGenerator
public Object getOutputTarget()
getOutputTarget
in class com.fasterxml.jackson.core.JsonGenerator
public int getOutputBuffered()
-1
from heregetOutputBuffered
in class com.fasterxml.jackson.core.JsonGenerator
public int getFormatFeatures()
getFormatFeatures
in class com.fasterxml.jackson.core.JsonGenerator
public com.fasterxml.jackson.core.JsonGenerator overrideFormatFeatures(int values, int mask)
overrideFormatFeatures
in class com.fasterxml.jackson.core.JsonGenerator
public ToXmlGenerator enable(ToXmlGenerator.Feature f)
public ToXmlGenerator disable(ToXmlGenerator.Feature f)
public final boolean isEnabled(ToXmlGenerator.Feature f)
public ToXmlGenerator configure(ToXmlGenerator.Feature f, boolean state)
public boolean canWriteFormattedNumbers()
canWriteFormattedNumbers
in class com.fasterxml.jackson.core.JsonGenerator
public boolean inRoot()
public XMLStreamWriter getStaxWriter()
XMLStreamWriter
. 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.
public void setNextIsAttribute(boolean isAttribute)
public void setNextIsUnwrapped(boolean isUnwrapped)
public void setNextIsCData(boolean isCData)
public final void setNextName(QName name)
public final boolean setNextNameIfMissing(QName name)
setNextName(javax.xml.namespace.QName)
, unless
a name has already been set.public void startWrappedValue(QName wrapperName, QName wrappedName) throws IOException
wrapperName
- Element used as wrapper around elements, if any (null if none)wrappedName
- Element used around individual content items (can not
be null)IOException
public void finishWrappedValue(QName wrapperName, QName wrappedName) throws IOException
IOException
public void writeRepeatedFieldName() throws IOException
IOException
public final void writeFieldName(String name) throws IOException
writeFieldName
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public final void writeStringField(String fieldName, String value) throws IOException
writeStringField
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public final void writeStartArray() throws IOException
writeStartArray
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public final void writeEndArray() throws IOException
writeEndArray
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public final void writeStartObject() throws IOException
writeStartObject
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public final void writeEndObject() throws IOException
writeEndObject
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public final void _handleStartObject() throws IOException
IOException
public final void _handleEndObject() throws IOException
IOException
public void writeFieldName(com.fasterxml.jackson.core.SerializableString name) throws IOException
writeFieldName
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void writeString(String text) throws IOException
writeString
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeString(char[] text, int offset, int len) throws IOException
writeString
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeString(com.fasterxml.jackson.core.SerializableString text) throws IOException
writeString
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void writeRawUTF8String(byte[] text, int offset, int length) throws IOException
writeRawUTF8String
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeUTF8String(byte[] text, int offset, int length) throws IOException
writeUTF8String
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeRawValue(String text) throws IOException
writeRawValue
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void writeRawValue(String text, int offset, int len) throws IOException
writeRawValue
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void writeRawValue(char[] text, int offset, int len) throws IOException
writeRawValue
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void writeRawValue(com.fasterxml.jackson.core.SerializableString text) throws IOException
writeRawValue
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void writeRaw(String text) throws IOException
writeRaw
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeRaw(String text, int offset, int len) throws IOException
writeRaw
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeRaw(char[] text, int offset, int len) throws IOException
writeRaw
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeRaw(char c) throws IOException
writeRaw
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
writeBinary
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeBoolean(boolean value) throws IOException
writeBoolean
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNull() throws IOException
writeNull
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(int i) throws IOException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(long l) throws IOException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(double d) throws IOException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(float f) throws IOException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(BigDecimal dec) throws IOException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(BigInteger value) throws IOException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
public void writeNumber(String encodedValue) throws IOException, UnsupportedOperationException
writeNumber
in class com.fasterxml.jackson.core.JsonGenerator
IOException
UnsupportedOperationException
protected final void _verifyValueWrite(String typeMsg) throws IOException
_verifyValueWrite
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class com.fasterxml.jackson.core.base.GeneratorBase
IOException
protected void _releaseBuffers()
_releaseBuffers
in class com.fasterxml.jackson.core.base.GeneratorBase
protected boolean checkNextIsUnwrapped()
protected void handleMissingName()
protected void _reportUnimplementedStax2(String missingMethod) throws IOException
IOException
Copyright © 2017 FasterXML. All rights reserved.