- 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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringpendingNameThe name for the next JSON object value.private JsonElementproductthe JSON element constructed by this writer.private static JsonPrimitiveSENTINEL_CLOSEDAdded to the top of the stack when this writer is closed to cause following ops to fail.private java.util.List<JsonElement>stackThe JsonElements and JsonArrays under modification, outermost to innermost.private static java.io.WriterUNWRITABLE_WRITER
-
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.JsonWritername(java.lang.String name)Encodes the property name.JsonWriternullValue()Encodesnull.private JsonElementpeek()private voidput(JsonElement value)JsonWritervalue(boolean value)Encodesvalue.JsonWritervalue(double 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
getSerializeNulls, isHtmlSafe, isLenient, jsonValue, setHtmlSafe, setIndent, setLenient, setSerializeNulls
-
-
-
-
Field Detail
-
UNWRITABLE_WRITER
private static final java.io.Writer UNWRITABLE_WRITER
-
SENTINEL_CLOSED
private static final JsonPrimitive SENTINEL_CLOSED
Added to the top of the stack when this writer is closed to cause following ops to fail.
-
stack
private final java.util.List<JsonElement> stack
The JsonElements and JsonArrays under modification, outermost to innermost.
-
pendingName
private java.lang.String pendingName
The name for the next JSON object value. If non-null, the top of the stack is a JsonObject.
-
product
private JsonElement product
the JSON element constructed by this writer.
-
-
Method Detail
-
get
public JsonElement get()
Returns the top level object produced by this writer.
-
peek
private JsonElement peek()
-
put
private void put(JsonElement value)
-
beginArray
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
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
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
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
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 be null.- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
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
-
nullValue
public JsonWriter nullValue() throws java.io.IOException
Description copied from class:JsonWriterEncodesnull.- Overrides:
nullValuein classJsonWriter- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
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
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
public JsonWriter value(double value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value. May not beNaNsorinfinities.- Returns:
- this writer.
- Throws:
java.io.IOException
-
value
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
public JsonWriter value(java.lang.Number value) throws java.io.IOException
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value. May not beNaNsorinfinities.- 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.
-
-