public class JsonWriter extends AbstractJsonWriter
Modifier and Type | Class and Description |
---|---|
static class |
JsonWriter.Format
Format definition for JSON.
|
AbstractJsonWriter.Type
Modifier and Type | Field and Description |
---|---|
protected JsonWriter.Format |
format |
protected com.thoughtworks.xstream.core.util.QuickWriter |
writer |
DROP_ROOT_MODE, EXPLICIT_MODE, IEEE_754_MODE, STRICT_MODE
Constructor and Description |
---|
JsonWriter(java.io.Writer writer) |
JsonWriter(java.io.Writer writer,
char[] lineIndenter)
Deprecated.
As of 1.4 use
instead |
JsonWriter(java.io.Writer writer,
char[] lineIndenter,
java.lang.String newLine)
Deprecated.
As of 1.4 use
instead |
JsonWriter(java.io.Writer writer,
char[] lineIndenter,
java.lang.String newLine,
int mode)
Deprecated.
As of 1.4 use
instead |
JsonWriter(java.io.Writer writer,
int mode)
Create a JsonWriter where the writer mode can be chosen.
|
JsonWriter(java.io.Writer writer,
int mode,
JsonWriter.Format format)
Create a JsonWriter where the writer mode can be chosen and the format definition is
provided.
|
JsonWriter(java.io.Writer writer,
int mode,
JsonWriter.Format format,
int bufferSize)
Create a JsonWriter.
|
JsonWriter(java.io.Writer writer,
JsonWriter.Format format)
Create a JsonWriter where the format is provided.
|
JsonWriter(java.io.Writer writer,
java.lang.String lineIndenter)
Deprecated.
As of 1.4 use
instead |
JsonWriter(java.io.Writer writer,
java.lang.String lineIndenter,
java.lang.String newLine)
Deprecated.
As of 1.4 use
instead |
Modifier and Type | Method and Description |
---|---|
protected void |
addLabel(java.lang.String name)
Add a label to a JSON object.
|
protected void |
addValue(java.lang.String value,
AbstractJsonWriter.Type type)
Add a value to a JSON object's label or to an array.
|
void |
close()
Close the writer, if necessary.
|
protected void |
endArray()
End the JSON array.
|
protected void |
endObject()
End the JSON object.
|
void |
flush()
Flush the writer, if necessary.
|
protected void |
nextElement()
Prepare a JSON object or array for another element.
|
protected void |
startArray()
Start a JSON array.
|
protected void |
startObject()
Start a JSON object.
|
HierarchicalStreamWriter |
underlyingWriter()
Return the underlying HierarchicalStreamWriter implementation.
|
addAttribute, endNode, getType, isArray, setValue, startNode, startNode
encodeAttribute, encodeNode
protected final com.thoughtworks.xstream.core.util.QuickWriter writer
protected final JsonWriter.Format format
public JsonWriter(java.io.Writer writer, char[] lineIndenter, java.lang.String newLine)
instead
public JsonWriter(java.io.Writer writer, char[] lineIndenter)
instead
public JsonWriter(java.io.Writer writer, java.lang.String lineIndenter, java.lang.String newLine)
instead
public JsonWriter(java.io.Writer writer, java.lang.String lineIndenter)
instead
public JsonWriter(java.io.Writer writer)
public JsonWriter(java.io.Writer writer, char[] lineIndenter, java.lang.String newLine, int mode)
instead
public JsonWriter(java.io.Writer writer, int mode)
writer
- the Writer
where the JSON is written tomode
- the JsonWriter modeJsonWriter(Writer, int, Format)
public JsonWriter(java.io.Writer writer, JsonWriter.Format format)
writer
- the Writer
where the JSON is written toformat
- the JSON format definitionJsonWriter(Writer, int, Format)
public JsonWriter(java.io.Writer writer, int mode, JsonWriter.Format format)
Following constants can be used as bit mask for the mode:
AbstractJsonWriter.DROP_ROOT_MODE
: drop the root nodeAbstractJsonWriter.STRICT_MODE
: do not throw ConversionException
, if writer should
generate invalid JSONAbstractJsonWriter.EXPLICIT_MODE
: ensure that all available data is explicitly written even if
addition objects must be addedwriter
- the Writer
where the JSON is written tomode
- the JsonWriter modeformat
- the JSON format definitionpublic JsonWriter(java.io.Writer writer, int mode, JsonWriter.Format format, int bufferSize)
writer
- the Writer
where the JSON is written tomode
- the JsonWriter modeformat
- the JSON format definitionbufferSize
- the buffer size of the internally used QuickWriterJsonWriter(Writer, int, Format)
public void flush()
HierarchicalStreamWriter
public void close()
HierarchicalStreamWriter
public HierarchicalStreamWriter underlyingWriter()
AbstractWriter
If a Converter needs to access methods of a specific HierarchicalStreamWriter implementation that are not defined in the HierarchicalStreamWriter interface, it should call this method before casting. This is because the writer passed to the Converter is often wrapped/decorated by another implementation to provide additional functionality (such as XPath tracking).
For example:
MySpecificWriter mySpecificWriter = (MySpecificWriter)writer; // INCORRECT! mySpecificWriter.doSomethingSpecific();
MySpecificWriter mySpecificWriter = (MySpecificWriter)writer.underlyingWriter(); // CORRECT! mySpecificWriter.doSomethingSpecific();
Implementations of HierarchicalStreamWriter should return 'this', unless they are a decorator, in which case they should delegate to whatever they are wrapping.
underlyingWriter
in interface HierarchicalStreamWriter
underlyingWriter
in class AbstractWriter
protected void startObject()
startObject
in class AbstractJsonWriter
protected void addLabel(java.lang.String name)
addLabel
in class AbstractJsonWriter
name
- the label's nameprotected void addValue(java.lang.String value, AbstractJsonWriter.Type type)
addValue
in class AbstractJsonWriter
value
- the value itselftype
- the JSON typeprotected void startArray()
startArray
in class AbstractJsonWriter
protected void nextElement()
nextElement
in class AbstractJsonWriter
protected void endArray()
endArray
in class AbstractJsonWriter
protected void endObject()
endObject
in class AbstractJsonWriter
Copyright © 2004–2024 XStream. All rights reserved.