|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.thoughtworks.xstream.io.AbstractWriter
com.thoughtworks.xstream.io.json.AbstractJsonWriter
com.thoughtworks.xstream.io.json.JsonWriter
public class JsonWriter
A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets rely on you NOT using XStream.addImplicitCollection(..).
| Nested Class Summary | |
|---|---|
static class |
JsonWriter.Format
Format definition for JSON. |
| Nested classes/interfaces inherited from class com.thoughtworks.xstream.io.json.AbstractJsonWriter |
|---|
AbstractJsonWriter.Type |
| Field Summary | |
|---|---|
protected JsonWriter.Format |
format
|
protected QuickWriter |
writer
|
| Fields inherited from class com.thoughtworks.xstream.io.json.AbstractJsonWriter |
|---|
DROP_ROOT_MODE, EXPLICIT_MODE, STRICT_MODE |
| Constructor Summary | |
|---|---|
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 |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class com.thoughtworks.xstream.io.json.AbstractJsonWriter |
|---|
addAttribute, endNode, isArray, setValue, startNode, startNode |
| Methods inherited from class com.thoughtworks.xstream.io.AbstractWriter |
|---|
encodeAttribute, encodeNode |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final QuickWriter writer
protected final JsonWriter.Format format
| Constructor Detail |
|---|
public JsonWriter(Writer writer,
char[] lineIndenter,
String newLine)
instead
public JsonWriter(Writer writer,
char[] lineIndenter)
instead
public JsonWriter(Writer writer,
String lineIndenter,
String newLine)
instead
public JsonWriter(Writer writer,
String lineIndenter)
instead
public JsonWriter(Writer writer)
public JsonWriter(Writer writer,
char[] lineIndenter,
String newLine,
int mode)
instead
public 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 added
writer - the Writer where the JSON is written tomode - the JsonWriter modeformat - the JSON format definition
public 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)| Method Detail |
|---|
public void flush()
HierarchicalStreamWriter
public void close()
HierarchicalStreamWriter
public 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 name
protected 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 AbstractJsonWriter
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||