com.fasterxml.jackson.xml.ser
Class ToXmlGenerator

java.lang.Object
  extended by org.codehaus.jackson.JsonGenerator
      extended by org.codehaus.jackson.impl.JsonGeneratorBase
          extended by com.fasterxml.jackson.xml.ser.ToXmlGenerator
All Implemented Interfaces:
Closeable, org.codehaus.jackson.Versioned

public final class ToXmlGenerator
extends org.codehaus.jackson.impl.JsonGeneratorBase

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.

Since:
1.6

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  org.codehaus.jackson.io.IOContext _ioContext
           
protected  boolean _nextIsAttribute
          Marker flag that indicates whether next name to write implies an attribute (true) or element (false)
protected  QName _nextName
          Element or attribute name to use for next output call.
protected  int _xmlFeatures
          Bit flag composed of bits that indicate which ToXmlGenerator.Features are enabled.
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 org.codehaus.jackson.impl.JsonGeneratorBase
_cfgNumbersAsStrings, _closed, _features, _objectCodec, _writeContext
 
Fields inherited from class org.codehaus.jackson.JsonGenerator
_cfgPrettyPrinter
 
Constructor Summary
ToXmlGenerator(org.codehaus.jackson.io.IOContext ctxt, int genericGeneratorFeatures, int xmlFeatures, org.codehaus.jackson.ObjectCodec codec, XMLStreamWriter sw)
           
 
Method Summary
 void _handleEndObject()
           
 void _handleStartObject()
           
protected  void _releaseBuffers()
           
protected  void _verifyValueWrite(String typeMsg)
           
 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 setNextName(QName name)
           
 void startWrappedValue(QName wrapperName, QName wrappedName)
          Methdod called when a structured (collection, array, map) is being output.
 org.codehaus.jackson.JsonGenerator useDefaultPrettyPrinter()
          Standard JSON indenter does not work well with XML, use default XML indenter instead.
 void writeBinary(org.codehaus.jackson.Base64Variant b64variant, byte[] data, int offset, int len)
           
 void writeBoolean(boolean state)
           
 void writeEndArray()
           
 void writeEndObject()
           
 void writeFieldName(org.codehaus.jackson.SerializableString name)
           
 void writeFieldName(org.codehaus.jackson.io.SerializedString name)
           
 void writeFieldName(String name)
           
 void writeNull()
           
 void writeNumber(BigDecimal dec)
           
 void writeNumber(BigInteger v)
           
 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(org.codehaus.jackson.SerializableString text)
           
 void writeString(String text)
           
 void writeStringField(String fieldName, String value)
           
 void writeUTF8String(byte[] text, int offset, int length)
           
 
Methods inherited from class org.codehaus.jackson.impl.JsonGeneratorBase
_cantHappen, _reportError, _reportUnsupportedOperation, _throwInternal, _writeEndArray, _writeEndObject, _writeSimpleObject, _writeStartArray, _writeStartObject, copyCurrentEvent, copyCurrentStructure, disable, enable, getCodec, getOutputContext, isClosed, isEnabled, setCodec, version, writeObject, writeRawValue, writeRawValue, writeRawValue, writeTree
 
Methods inherited from class org.codehaus.jackson.JsonGenerator
canUseSchema, configure, disableFeature, enableFeature, getCharacterEscapes, getHighestEscapedChar, getOutputTarget, isFeatureEnabled, setCharacterEscapes, setFeature, setHighestNonEscapedChar, setPrettyPrinter, setSchema, writeArrayFieldStart, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeNullField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart
 
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

_ioContext

protected final org.codehaus.jackson.io.IOContext _ioContext

_xmlFeatures

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


_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)


_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(org.codehaus.jackson.io.IOContext ctxt,
                      int genericGeneratorFeatures,
                      int xmlFeatures,
                      org.codehaus.jackson.ObjectCodec codec,
                      XMLStreamWriter sw)
Method Detail

initGenerator

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

Throws:
IOException
org.codehaus.jackson.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.

Since:
1.7

setNextIsAttribute

public void setNextIsAttribute(boolean isAttribute)

setNextName

public final void setNextName(QName name)

startWrappedValue

public void startWrappedValue(QName wrapperName,
                              QName wrappedName)
                       throws IOException,
                              org.codehaus.jackson.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
org.codehaus.jackson.JsonGenerationException

finishWrappedValue

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

Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeFieldName

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

writeStringField

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

writeStartArray

public final void writeStartArray()
                           throws IOException,
                                  org.codehaus.jackson.JsonGenerationException
Overrides:
writeStartArray in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeEndArray

public final void writeEndArray()
                         throws IOException,
                                org.codehaus.jackson.JsonGenerationException
Overrides:
writeEndArray in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeStartObject

public final void writeStartObject()
                            throws IOException,
                                   org.codehaus.jackson.JsonGenerationException
Overrides:
writeStartObject in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeEndObject

public final void writeEndObject()
                          throws IOException,
                                 org.codehaus.jackson.JsonGenerationException
Overrides:
writeEndObject in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

_handleStartObject

public final void _handleStartObject()
                              throws IOException,
                                     org.codehaus.jackson.JsonGenerationException
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

_handleEndObject

public final void _handleEndObject()
                            throws IOException,
                                   org.codehaus.jackson.JsonGenerationException
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeFieldName

public void writeFieldName(org.codehaus.jackson.io.SerializedString name)
                    throws IOException,
                           org.codehaus.jackson.JsonGenerationException
Overrides:
writeFieldName in class org.codehaus.jackson.JsonGenerator
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeFieldName

public void writeFieldName(org.codehaus.jackson.SerializableString name)
                    throws IOException,
                           org.codehaus.jackson.JsonGenerationException
Overrides:
writeFieldName in class org.codehaus.jackson.JsonGenerator
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeString

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

writeString

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

writeString

public void writeString(org.codehaus.jackson.SerializableString text)
                 throws IOException,
                        org.codehaus.jackson.JsonGenerationException
Overrides:
writeString in class org.codehaus.jackson.JsonGenerator
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeRawUTF8String

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

writeUTF8String

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

writeRaw

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

writeRaw

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

writeRaw

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

writeRaw

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

writeBinary

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

writeBoolean

public void writeBoolean(boolean state)
                  throws IOException,
                         org.codehaus.jackson.JsonGenerationException
Specified by:
writeBoolean in class org.codehaus.jackson.JsonGenerator
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeNull

public void writeNull()
               throws IOException,
                      org.codehaus.jackson.JsonGenerationException
Specified by:
writeNull in class org.codehaus.jackson.JsonGenerator
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeNumber

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

writeNumber

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

writeNumber

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

writeNumber

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

writeNumber

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

writeNumber

public void writeNumber(BigInteger v)
                 throws IOException,
                        org.codehaus.jackson.JsonGenerationException
Specified by:
writeNumber in class org.codehaus.jackson.JsonGenerator
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

writeNumber

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

_verifyValueWrite

protected final void _verifyValueWrite(String typeMsg)
                                throws IOException,
                                       org.codehaus.jackson.JsonGenerationException
Specified by:
_verifyValueWrite in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException
org.codehaus.jackson.JsonGenerationException

useDefaultPrettyPrinter

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

Overrides:
useDefaultPrettyPrinter in class org.codehaus.jackson.impl.JsonGeneratorBase

flush

public final void flush()
                 throws IOException
Specified by:
flush in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class org.codehaus.jackson.impl.JsonGeneratorBase
Throws:
IOException

_releaseBuffers

protected void _releaseBuffers()
Specified by:
_releaseBuffers in class org.codehaus.jackson.impl.JsonGeneratorBase

handleMissingName

protected void handleMissingName()


Copyright © 2011 fasterxml.com. All Rights Reserved.