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 |
|---|---|
private int |
depth |
protected JsonWriter.Format |
format |
private boolean |
newLineProposed |
protected 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.
|
private void |
endNewLine() |
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.
|
private void |
startNewLine() |
protected void |
startObject()
Start a JSON object.
|
HierarchicalStreamWriter |
underlyingWriter()
Return the underlying HierarchicalStreamWriter implementation.
|
private void |
writeNewLine() |
private void |
writeText(java.lang.String text) |
addAttribute, endNode, getType, isArray, setValue, startNode, startNodeencodeAttribute, encodeNodeprotected final QuickWriter writer
protected final JsonWriter.Format format
private int depth
private boolean newLineProposed
public JsonWriter(java.io.Writer writer,
char[] lineIndenter,
java.lang.String newLine)
insteadpublic JsonWriter(java.io.Writer writer,
char[] lineIndenter)
insteadpublic JsonWriter(java.io.Writer writer,
java.lang.String lineIndenter,
java.lang.String newLine)
insteadpublic JsonWriter(java.io.Writer writer,
java.lang.String lineIndenter)
insteadpublic JsonWriter(java.io.Writer writer)
public JsonWriter(java.io.Writer writer,
char[] lineIndenter,
java.lang.String newLine,
int mode)
insteadpublic 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()
HierarchicalStreamWriterpublic void close()
HierarchicalStreamWriterpublic HierarchicalStreamWriter underlyingWriter()
AbstractWriterIf 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 HierarchicalStreamWriterunderlyingWriter in class AbstractWriterprotected void startObject()
startObject in class AbstractJsonWriterprotected void addLabel(java.lang.String name)
addLabel in class AbstractJsonWritername - the label's nameprotected void addValue(java.lang.String value,
AbstractJsonWriter.Type type)
addValue in class AbstractJsonWritervalue - the value itselftype - the JSON typeprotected void startArray()
startArray in class AbstractJsonWriterprotected void nextElement()
nextElement in class AbstractJsonWriterprotected void endArray()
endArray in class AbstractJsonWriterprotected void endObject()
endObject in class AbstractJsonWriterprivate void startNewLine()
private void endNewLine()
private void writeNewLine()
private void writeText(java.lang.String text)