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(Writer writer)  | 
JsonWriter(Writer writer,
          char[] lineIndenter)
Deprecated. 
 
As of 1.4 use  
instead | 
JsonWriter(Writer writer,
          char[] lineIndenter,
          String newLine)
Deprecated. 
 
As of 1.4 use  
instead | 
JsonWriter(Writer writer,
          char[] lineIndenter,
          String newLine,
          int mode)
Deprecated. 
 
As of 1.4 use  
instead | 
JsonWriter(Writer writer,
          int mode)
Create a JsonWriter where the writer mode can be chosen. 
 | 
JsonWriter(Writer writer,
          int mode,
          JsonWriter.Format format)
Create a JsonWriter where the writer mode can be chosen and the format definition is
 provided. 
 | 
JsonWriter(Writer writer,
          int mode,
          JsonWriter.Format format,
          int bufferSize)
Create a JsonWriter. 
 | 
JsonWriter(Writer writer,
          JsonWriter.Format format)
Create a JsonWriter where the format is provided. 
 | 
JsonWriter(Writer writer,
          String lineIndenter)
Deprecated. 
 
As of 1.4 use  
instead | 
JsonWriter(Writer writer,
          String lineIndenter,
          String newLine)
Deprecated. 
 
As of 1.4 use  
instead | 
| Modifier and Type | Method and Description | 
|---|---|
protected void | 
addLabel(String name)
Add a label to a JSON object. 
 | 
protected void | 
addValue(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, startNodeencodeAttribute, encodeNodeprotected final com.thoughtworks.xstream.core.util.QuickWriter writer
protected final JsonWriter.Format format
public JsonWriter(Writer writer, char[] lineIndenter, String newLine)
insteadpublic JsonWriter(Writer writer, String lineIndenter, String newLine)
insteadpublic JsonWriter(Writer writer)
public JsonWriter(Writer writer, char[] lineIndenter, String newLine, int mode)
insteadpublic JsonWriter(Writer writer, int mode)
writer - the Writer where the JSON is written tomode - the JsonWriter modeJsonWriter(Writer, int, Format)public JsonWriter(Writer writer, JsonWriter.Format format)
writer - the Writer where the JSON is written toformat - the JSON format definitionJsonWriter(Writer, int, Format)public JsonWriter(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(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(String name)
addLabel in class AbstractJsonWritername - the label's nameprotected void addValue(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 AbstractJsonWriterCopyright © 2004–2016 XStream. All rights reserved.