com.fasterxml.jackson.dataformat.xml.ser
Class ToXmlGenerator

java.lang.Object
  extended by com.fasterxml.jackson.core.JsonGenerator
      extended by com.fasterxml.jackson.core.base.GeneratorBase
          extended by com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator
All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned, Closeable, Flushable

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.


Nested Class Summary
static class ToXmlGenerator.Feature
          Enumeration that defines all togglable extra XML-specific features
 
Field Summary
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  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 _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  int _xmlFeatures
          Bit flag composed of bits that indicate which ToXmlGenerator.Features are enabled.
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...
 
Fields inherited from class com.fasterxml.jackson.core.base.GeneratorBase
_cfgNumbersAsStrings, _closed, _features, _objectCodec, _writeContext
 
Fields inherited from class com.fasterxml.jackson.core.JsonGenerator
_cfgPrettyPrinter
 
Constructor Summary
ToXmlGenerator(com.fasterxml.jackson.core.io.IOContext ctxt, int genericGeneratorFeatures, int xmlFeatures, com.fasterxml.jackson.core.ObjectCodec codec, XMLStreamWriter sw)
           
 
Method Summary
 void _handleEndObject()
           
 void _handleStartObject()
           
protected  void _releaseBuffers()
           
protected  void _reportUnimplementedStax2(String missingMethod)
          Method called
protected  void _verifyValueWrite(String typeMsg)
           
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()
           
 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 isEnabled(ToXmlGenerator.Feature f)
           
 void setNextIsAttribute(boolean isAttribute)
           
 void setNextIsUnwrapped(boolean isUnwrapped)
           
 void setNextName(QName name)
           
 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.
 com.fasterxml.jackson.core.JsonGenerator useDefaultPrettyPrinter()
          Standard JSON indenter does not work well with XML, use default XML indenter instead.
 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 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)
           
 
Methods inherited from class com.fasterxml.jackson.core.base.GeneratorBase
_cantHappen, _reportError, _reportUnsupportedOperation, _throwInternal, _writeSimpleObject, copyCurrentEvent, copyCurrentStructure, disable, enable, getCodec, getOutputContext, isClosed, isEnabled, setCodec, version, writeBinary, writeObject, writeRawValue, writeRawValue, writeRawValue, writeTree
 
Methods inherited from class com.fasterxml.jackson.core.JsonGenerator
canUseSchema, configure, getCharacterEscapes, getHighestEscapedChar, getOutputTarget, getPrettyPrinter, getSchema, setCharacterEscapes, setHighestNonEscapedChar, setRootValueSeparator, setSchema, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeNullField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeRaw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_UNKNOWN_ELEMENT

protected static final 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 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 use writeRaw(java.lang.String) calls.


_ioContext

protected final com.fasterxml.jackson.core.io.IOContext _ioContext

_xmlFeatures

protected int _xmlFeatures
Bit flag composed of bits that indicate which ToXmlGenerator.Features are enabled.


_xmlPrettyPrinter

protected XmlPrettyPrinter _xmlPrettyPrinter
We may need to use XML-specific indentation as well


_nextName

protected 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.


_elementNameStack

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

Constructor Detail

ToXmlGenerator

public ToXmlGenerator(com.fasterxml.jackson.core.io.IOContext ctxt,
                      int genericGeneratorFeatures,
                      int xmlFeatures,
                      com.fasterxml.jackson.core.ObjectCodec codec,
                      XMLStreamWriter sw)
Method Detail

initGenerator

public void initGenerator()
                   throws IOException,
                          com.fasterxml.jackson.core.JsonGenerationException
Method called before writing any other output, to optionally output XML declaration.

Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

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)

getStaxWriter

public XMLStreamWriter getStaxWriter()
Method that allows application direct access to underlying Stax 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.


setNextIsAttribute

public void setNextIsAttribute(boolean isAttribute)

setNextIsUnwrapped

public void setNextIsUnwrapped(boolean isUnwrapped)

setNextName

public final void setNextName(QName name)

startWrappedValue

public void startWrappedValue(QName wrapperName,
                              QName wrappedName)
                       throws IOException,
                              com.fasterxml.jackson.core.JsonGenerationException
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:
IOException
com.fasterxml.jackson.core.JsonGenerationException

finishWrappedValue

public void finishWrappedValue(QName wrapperName,
                               QName wrappedName)
                        throws IOException,
                               com.fasterxml.jackson.core.JsonGenerationException
Method called after a structured collection output has completed

Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeFieldName

public final void writeFieldName(String name)
                          throws IOException,
                                 com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeFieldName in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeStringField

public final void writeStringField(String fieldName,
                                   String value)
                            throws IOException,
                                   com.fasterxml.jackson.core.JsonGenerationException
Overrides:
writeStringField in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeStartArray

public final void writeStartArray()
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeStartArray in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeEndArray

public final void writeEndArray()
                         throws IOException,
                                com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeEndArray in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeStartObject

public final void writeStartObject()
                            throws IOException,
                                   com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeStartObject in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeEndObject

public final void writeEndObject()
                          throws IOException,
                                 com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeEndObject in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

_handleStartObject

public final void _handleStartObject()
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonGenerationException
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

_handleEndObject

public final void _handleEndObject()
                            throws IOException,
                                   com.fasterxml.jackson.core.JsonGenerationException
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeFieldName

public void writeFieldName(com.fasterxml.jackson.core.SerializableString name)
                    throws IOException,
                           com.fasterxml.jackson.core.JsonGenerationException
Overrides:
writeFieldName in class com.fasterxml.jackson.core.base.GeneratorBase
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeString

public void writeString(String text)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeString in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeString

public void writeString(char[] text,
                        int offset,
                        int len)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeString in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeString

public void writeString(com.fasterxml.jackson.core.SerializableString text)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Overrides:
writeString in class com.fasterxml.jackson.core.base.GeneratorBase
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeRawUTF8String

public void writeRawUTF8String(byte[] text,
                               int offset,
                               int length)
                        throws IOException,
                               com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeRawUTF8String in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeUTF8String

public void writeUTF8String(byte[] text,
                            int offset,
                            int length)
                     throws IOException,
                            com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeUTF8String in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeRaw

public void writeRaw(String text)
              throws IOException,
                     com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeRaw in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeRaw

public void writeRaw(String text,
                     int offset,
                     int len)
              throws IOException,
                     com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeRaw in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeRaw

public void writeRaw(char[] text,
                     int offset,
                     int len)
              throws IOException,
                     com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeRaw in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeRaw

public void writeRaw(char c)
              throws IOException,
                     com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeRaw in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeBinary

public void writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant,
                        byte[] data,
                        int offset,
                        int len)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeBinary in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeBoolean

public void writeBoolean(boolean value)
                  throws IOException,
                         com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeBoolean in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNull

public void writeNull()
               throws IOException,
                      com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNull in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(int i)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(long l)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(double d)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(float f)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(BigDecimal dec)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(BigInteger value)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

writeNumber

public void writeNumber(String encodedValue)
                 throws IOException,
                        com.fasterxml.jackson.core.JsonGenerationException,
                        UnsupportedOperationException
Specified by:
writeNumber in class com.fasterxml.jackson.core.JsonGenerator
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException
UnsupportedOperationException

_verifyValueWrite

protected final void _verifyValueWrite(String typeMsg)
                                throws IOException,
                                       com.fasterxml.jackson.core.JsonGenerationException
Specified by:
_verifyValueWrite in class com.fasterxml.jackson.core.base.GeneratorBase
Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException

useDefaultPrettyPrinter

public final com.fasterxml.jackson.core.JsonGenerator useDefaultPrettyPrinter()
Standard JSON indenter does not work well with XML, use default XML indenter instead.

Overrides:
useDefaultPrettyPrinter in class com.fasterxml.jackson.core.base.GeneratorBase

setPrettyPrinter

public com.fasterxml.jackson.core.JsonGenerator setPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp)
Overrides:
setPrettyPrinter in class com.fasterxml.jackson.core.JsonGenerator

flush

public final void flush()
                 throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class com.fasterxml.jackson.core.base.GeneratorBase
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class com.fasterxml.jackson.core.base.GeneratorBase
Throws:
IOException

_releaseBuffers

protected void _releaseBuffers()
Specified by:
_releaseBuffers in class com.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(String missingMethod)
                                  throws IOException
Method called

Throws:
IOException


Copyright © 2012 FasterXML. All Rights Reserved.