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:
Closeable
,Flushable
,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 JsonWriter
beginArray()
Begins encoding a new array.JsonWriter
beginObject()
Begins encoding a new object.void
close()
Flushes and closes this writer and the underlyingWriter
.JsonWriter
endArray()
Ends encoding the current array.JsonWriter
endObject()
Ends encoding the current object.void
flush()
Ensures all buffered data is written to the underlyingWriter
and flushes that writer.JsonElement
get()
Returns the top level object produced by this writer.JsonWriter
name(String name)
Encodes the property name.JsonWriter
nullValue()
Encodesnull
.JsonWriter
value(boolean value)
Encodesvalue
.JsonWriter
value(double value)
Encodesvalue
.JsonWriter
value(long value)
Encodesvalue
.JsonWriter
value(Boolean value)
Encodesvalue
.JsonWriter
value(Number value)
Encodesvalue
.JsonWriter
value(String value)
Encodesvalue
.-
Methods inherited from class com.google.gson.stream.JsonWriter
getSerializeNulls, isHtmlSafe, isLenient, jsonValue, setHtmlSafe, setIndent, setLenient, setSerializeNulls
-
-
-
-
Method Detail
-
get
public JsonElement get()
Returns the top level object produced by this writer.
-
beginArray
public JsonWriter beginArray() throws IOException
Description copied from class:JsonWriter
Begins encoding a new array. Each call to this method must be paired with a call toJsonWriter.endArray()
.- Overrides:
beginArray
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
endArray
public JsonWriter endArray() throws IOException
Description copied from class:JsonWriter
Ends encoding the current array.- Overrides:
endArray
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
beginObject
public JsonWriter beginObject() throws IOException
Description copied from class:JsonWriter
Begins encoding a new object. Each call to this method must be paired with a call toJsonWriter.endObject()
.- Overrides:
beginObject
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
endObject
public JsonWriter endObject() throws IOException
Description copied from class:JsonWriter
Ends encoding the current object.- Overrides:
endObject
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
name
public JsonWriter name(String name) throws IOException
Description copied from class:JsonWriter
Encodes the property name.- Overrides:
name
in classJsonWriter
- Parameters:
name
- the name of the forthcoming value. May not be null.- Returns:
- this writer.
- Throws:
IOException
-
value
public JsonWriter value(String value) throws IOException
Description copied from class:JsonWriter
Encodesvalue
.- Overrides:
value
in classJsonWriter
- Parameters:
value
- the literal string value, or null to encode a null literal.- Returns:
- this writer.
- Throws:
IOException
-
nullValue
public JsonWriter nullValue() throws IOException
Description copied from class:JsonWriter
Encodesnull
.- Overrides:
nullValue
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
value
public JsonWriter value(boolean value) throws IOException
Description copied from class:JsonWriter
Encodesvalue
.- Overrides:
value
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
value
public JsonWriter value(Boolean value) throws IOException
Description copied from class:JsonWriter
Encodesvalue
.- Overrides:
value
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
value
public JsonWriter value(double value) throws IOException
Description copied from class:JsonWriter
Encodesvalue
.- Overrides:
value
in classJsonWriter
- Parameters:
value
- a finite value. May not beNaNs
orinfinities
.- Returns:
- this writer.
- Throws:
IOException
-
value
public JsonWriter value(long value) throws IOException
Description copied from class:JsonWriter
Encodesvalue
.- Overrides:
value
in classJsonWriter
- Returns:
- this writer.
- Throws:
IOException
-
value
public JsonWriter value(Number value) throws IOException
Description copied from class:JsonWriter
Encodesvalue
.- Overrides:
value
in classJsonWriter
- Parameters:
value
- a finite value. May not beNaNs
orinfinities
.- Returns:
- this writer.
- Throws:
IOException
-
flush
public void flush() throws IOException
Description copied from class:JsonWriter
Ensures all buffered data is written to the underlyingWriter
and flushes that writer.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classJsonWriter
- Throws:
IOException
-
close
public void close() throws IOException
Description copied from class:JsonWriter
Flushes and closes this writer and the underlyingWriter
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classJsonWriter
- Throws:
IOException
- if the JSON document is incomplete.
-
-