Class JsonXMLStreamWriter
java.lang.Object
org.apache.synapse.commons.staxon.core.base.AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter
- All Implemented Interfaces:
XMLStreamWriter
public class JsonXMLStreamWriter
extends AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
JSON XML stream writer.
Limitations
- Mixed content (e.g.
<alice>bob<edgar/></alice>) is not supported. writeDTD(...)andwriteEntityRef(...)are not supported.writeCData(...)delegates to writeCharacters(...).writeComment(...)does nothing.writeProcessingInstruction(...)does nothing (except for targetxml-multiple, see below).
The writer may consume processing instructions
(e.g. <?xml-multiple element-name?>) to properly insert JSON array tokens ('['
and ']'). The client provides this instruction through the
AbstractXMLStreamWriter.writeProcessingInstruction(String, String) method,
passing the (possibly prefixed) field name as data e.g.
...
writer.writeProcessingInstruction("xml-multiple", "item");
for (Item item : items) {
writer.writeStartElement("item");
...
writer.writeEndElement();
}
...
The element name passed as processing instruction data is optional. If omitted, the next element within the current scope will start an array. Note, that this method does not allow to create empty arrays (in fact, the above code sample could create unexpected results, if the name would have been omitted and collection were empty).
-
Constructor Summary
ConstructorsConstructorDescriptionJsonXMLStreamWriter(JsonStreamTarget target, boolean repairNamespaces, boolean multiplePI, char namespaceSeparator, boolean namespaceDeclarations) Create writer instance.JsonXMLStreamWriter(JsonStreamTarget target, boolean repairNamespaces, boolean multiplePI, char namespaceSeparator, boolean namespaceDeclarations, boolean xmlNilReadWriteEnabled, boolean xmlWriteNullForEmptyElement) Create writer instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()protected voidWrite attribute.voidwriteAttribute(String prefix, String namespaceURI, String localName, String value) voidwriteBoolean(Boolean value) Write boolean value.protected voidWrite characters/comment/dtd/entity data.voidvoidprotected voidWrite end element tag.voidwriteNamespace(String prefix, String namespaceURI) protected voidwriteNsDecl(String prefix, String namespaceURI) Write namespace declaration.voidwriteNumber(Number value) Write number value.protected voidRead processing instruction.voidwriteStartArray(String fieldName) voidwriteStartDocument(String encoding, String version) protected org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfowriteStartElementTag(String prefix, String localName, String namespaceURI) Write open start element tag.protected voidWrite close start element tag.Methods inherited from class org.apache.synapse.commons.staxon.core.base.AbstractXMLStreamWriter
getNamespaceContext, getPrefix, getProperty, getScope, isStartDocumentWritten, setDefaultNamespace, setNamespaceContext, setPrefix, writeAttribute, writeAttribute, writeCData, writeCharacters, writeCharacters, writeCharacters, writeComment, writeDefaultNamespace, writeDTD, writeEmptyElement, writeEmptyElement, writeEmptyElement, writeEndElement, writeEntityRef, writeProcessingInstruction, writeProcessingInstruction, writeStartDocument, writeStartDocument, writeStartElement, writeStartElement, writeStartElement
-
Constructor Details
-
JsonXMLStreamWriter
public JsonXMLStreamWriter(JsonStreamTarget target, boolean repairNamespaces, boolean multiplePI, char namespaceSeparator, boolean namespaceDeclarations) Create writer instance.- Parameters:
target- stream targetrepairNamespaces- repair NamespacesmultiplePI- whether to consume<xml-multiple?>PIs to trigger array startnamespaceSeparator- namespace prefix separatornamespaceDeclarations- whether to write namespace declarations
-
JsonXMLStreamWriter
public JsonXMLStreamWriter(JsonStreamTarget target, boolean repairNamespaces, boolean multiplePI, char namespaceSeparator, boolean namespaceDeclarations, boolean xmlNilReadWriteEnabled, boolean xmlWriteNullForEmptyElement) Create writer instance.- Parameters:
target- stream targetrepairNamespaces- repair NamespacesmultiplePI- whether to consume<xml-multiple?>PIs to trigger array startnamespaceSeparator- namespace prefix separatornamespaceDeclarations- whether to write namespace declarationsxmlNilReadWriteEnabled- Supports reading and writing of XML Nil elements as defined by http://www.w3.org/TR/xmlschema-1/#xsi_nil when the XML/JSON inputs contains nil/null values.xmlWriteNullForEmptyElement- write null or "" for XML empty elements without nil attribute
-
-
Method Details
-
writeStartElementTag
protected org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo writeStartElementTag(String prefix, String localName, String namespaceURI) throws XMLStreamException Description copied from class:AbstractXMLStreamWriterWrite open start element tag. The returned scope info is stored in the new scope and will be available viagetScope().getInfo().- Specified by:
writeStartElementTagin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Parameters:
prefix- element prefix (may beXMLConstants.DEFAULT_NS_PREFIX)localName- local namenamespaceURI- namespace URI- Returns:
- new scope info
- Throws:
XMLStreamException
-
writeStartElementTagEnd
Description copied from class:AbstractXMLStreamWriterWrite close start element tag.- Specified by:
writeStartElementTagEndin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
writeEndElementTag
Description copied from class:AbstractXMLStreamWriterWrite end element tag.- Specified by:
writeEndElementTagin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttributein interfaceXMLStreamWriter- Overrides:
writeAttributein classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
writeNamespace
- Specified by:
writeNamespacein interfaceXMLStreamWriter- Overrides:
writeNamespacein classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
writeAttr
protected void writeAttr(String prefix, String localName, String namespaceURI, String value) throws XMLStreamException Description copied from class:AbstractXMLStreamWriterWrite attribute.- Specified by:
writeAttrin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Parameters:
prefix- attribute prefix (may beXMLConstants.DEFAULT_NS_PREFIX)localName- local namenamespaceURI- namespace URIvalue- attribute value- Throws:
XMLStreamException
-
writeNsDecl
Description copied from class:AbstractXMLStreamWriterWrite namespace declaration.- Specified by:
writeNsDeclin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Parameters:
prefix- namespace prefixnamespaceURI- namespace URI- Throws:
XMLStreamException
-
writeData
Description copied from class:AbstractXMLStreamWriterWrite characters/comment/dtd/entity data.- Specified by:
writeDatain classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Parameters:
data- text/datatype- one ofCHARACTERS, COMMENT, CDATA, DTD, ENTITY_REFERENCE, SPACE- Throws:
XMLStreamException
-
writeStartDocument
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Overrides:
writeStartDocumentin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
writeEndDocument
- Specified by:
writeEndDocumentin interfaceXMLStreamWriter- Overrides:
writeEndDocumentin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
writeStartArray
- Throws:
XMLStreamException
-
writeEndArray
- Throws:
XMLStreamException
-
close
- Specified by:
closein interfaceXMLStreamWriter- Overrides:
closein classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Throws:
XMLStreamException
-
flush
- Throws:
XMLStreamException
-
writePI
Description copied from class:AbstractXMLStreamWriterRead processing instruction.- Specified by:
writePIin classAbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>- Parameters:
target- PI targetdata- PI data (may benull)- Throws:
XMLStreamException
-
writeNumber
Write number value.- Parameters:
value-- Throws:
XMLStreamException
-
writeBoolean
Write boolean value.- Parameters:
value-- Throws:
XMLStreamException
-