Package com.google.gson.internal.bind
Class JsonTreeWriter
- java.lang.Object
-
- com.google.gson.stream.JsonWriter
-
- com.google.gson.internal.bind.JsonTreeWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public final class JsonTreeWriter extends JsonWriter
This writer creates a JsonElement.
-
-
Constructor Summary
Constructors Constructor Description JsonTreeWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonWriterbeginArray()Begins encoding a new array.JsonWriterbeginObject()Begins encoding a new object.voidclose()Flushes and closes this writer and the underlyingWriter.JsonWriterendArray()Ends encoding the current array.JsonWriterendObject()Ends encoding the current object.voidflush()Ensures all buffered data is written to the underlyingWriterand flushes that writer.JsonElementget()Returns the top level object produced by this writer.JsonWriterjsonValue(java.lang.String value)Writesvaluedirectly to the writer without quoting or escaping.JsonWritername(java.lang.String name)Encodes the property name.JsonWriternullValue()Encodesnull.JsonWritervalue(boolean value)Encodesvalue.JsonWritervalue(double value)Encodesvalue.JsonWritervalue(float value)Encodesvalue.JsonWritervalue(long value)Encodesvalue.JsonWritervalue(java.lang.Boolean value)Encodesvalue.JsonWritervalue(java.lang.Number value)Encodesvalue.JsonWritervalue(java.lang.String value)Encodesvalue.-
Methods inherited from class com.google.gson.stream.JsonWriter
getFormattingStyle, getSerializeNulls, getStrictness, isHtmlSafe, isLenient, setFormattingStyle, setHtmlSafe, setIndent, setLenient, setSerializeNulls, setStrictness
-
-
-
-
Method Detail
-
get
public JsonElement get()
Returns the top level object produced by this writer.
-
beginArray
@CanIgnoreReturnValue public JsonWriter beginArray() throws java.io.IOException
Description copied from class:JsonWriterBegins encoding a new array. Each call to this method must be paired with a call toJsonWriter.endArray().- Overrides:
beginArrayin classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
endArray
@CanIgnoreReturnValue public JsonWriter endArray() throws java.io.IOException
Description copied from class:JsonWriterEnds encoding the current array.- Overrides:
endArrayin classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
beginObject
@CanIgnoreReturnValue public JsonWriter beginObject() throws java.io.IOException
Description copied from class:JsonWriterBegins encoding a new object. Each call to this method must be paired with a call toJsonWriter.endObject().- Overrides:
beginObjectin classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
endObject
@CanIgnoreReturnValue public JsonWriter endObject() throws java.io.IOException
Description copied from class:JsonWriterEnds encoding the current object.- Overrides:
endObjectin classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
name
@CanIgnoreReturnValue public JsonWriter name(java.lang.String name) throws java.io.IOException
Description copied from class:JsonWriterEncodes the property name.- Overrides:
namein classJsonWriter- Parameters:
name- the name of the forthcoming value. May not benull.- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(java.lang.String value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- the literal string value, or null to encode a null literal.- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(boolean value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(java.lang.Boolean value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(float value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value, or iflenient, alsoNaNorinfinity.- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(double value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value, or iflenient, alsoNaNorinfinity.- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(long value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
@CanIgnoreReturnValue public JsonWriter value(java.lang.Number value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue. The value is written by directly writing theObject.toString()result to JSON. Implementations must make sure that the result represents a valid JSON number.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value, or iflenient, alsoNaNorinfinity.- Returns:
- this writer.
- Throws:
java.io.IOException
-
nullValue
@CanIgnoreReturnValue public JsonWriter nullValue() throws java.io.IOException
Description copied from class:JsonWriterEncodesnull.- Overrides:
nullValuein classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
jsonValue
public JsonWriter jsonValue(java.lang.String value) throws java.io.IOException
Description copied from class:JsonWriterWritesvaluedirectly to the writer without quoting or escaping. This might not be supported by all implementations, if not supported anUnsupportedOperationExceptionis thrown.- Overrides:
jsonValuein classJsonWriter- Parameters:
value- the literal string value, or null to encode a null literal.- Returns:
- this writer.
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionDescription copied from class:JsonWriterEnsures all buffered data is written to the underlyingWriterand flushes that writer.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classJsonWriter- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionDescription copied from class:JsonWriterFlushes and closes this writer and the underlyingWriter.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classJsonWriter- Throws:
java.io.IOException- if the JSON document is incomplete.
-
-