Top Description Fields Constructors Methods
com.google.gson.internal.bind

public final Class JsonTreeWriter

extends JsonWriter
Class Inheritance
Imports
com.google.errorprone.annotations.CanIgnoreReturnValue, com.google.gson.JsonArray, .JsonElement, .JsonNull, .JsonObject, .JsonPrimitive, com.google.gson.stream.JsonWriter, java.io.IOException, .Writer, java.util.ArrayList, .List, .Objects

This writer creates a JsonElement.

Field Summary

Modifier and TypeField and Description
private String
pendingName

The name for the next JSON object value.

private JsonElement
product

the JSON element constructed by this writer.

private static final JsonPrimitive
SENTINEL_CLOSED

Added to the top of the stack when this writer is closed to cause following ops to fail.

private final List<JsonElement>
stack

Hides com.google.gson.stream.JsonWriter.stack.

The JsonElements and JsonArrays under modification, outermost to innermost.
private static final Writer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public JsonWriter
beginArray()

Overrides com.google.gson.stream.JsonWriter.beginArray.

Begins encoding a new array.

public JsonWriter
beginObject()

Overrides com.google.gson.stream.JsonWriter.beginObject.

Begins encoding a new object.

public void
close()

Overrides com.google.gson.stream.JsonWriter.close.

Implements java.io.Closeable.close.

Flushes and closes this writer and the underlying Writer.

public JsonWriter
endArray()

Overrides com.google.gson.stream.JsonWriter.endArray.

Ends encoding the current array.

public JsonWriter
endObject()

Overrides com.google.gson.stream.JsonWriter.endObject.

Ends encoding the current object.

public void
flush()

Overrides com.google.gson.stream.JsonWriter.flush.

Implements java.io.Flushable.flush.

Ensures all buffered data is written to the underlying Writer and flushes that writer.

public JsonElement
get()

Returns the top level object produced by this writer.

public JsonWriter
jsonValue(String value)

Overrides com.google.gson.stream.JsonWriter.jsonValue.

Writes value directly to the writer without quoting or escaping.

public JsonWriter
name(String name)

Overrides com.google.gson.stream.JsonWriter.name.

Encodes the property name.

public JsonWriter
private JsonElement
peek()

Hides com.google.gson.stream.JsonWriter.peek.

Returns the value on the top of the stack.

private void
public JsonWriter
value(String value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

public JsonWriter
value(boolean value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

public JsonWriter
value(Boolean value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

public JsonWriter
value(float value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

public JsonWriter
value(double value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

public JsonWriter
value(long value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

public JsonWriter
value(Number value)

Overrides com.google.gson.stream.JsonWriter.value.

Encodes value.

Inherited from com.google.gson.stream.JsonWriter:
getFormattingStylegetSerializeNullsgetStrictnessisHtmlSafeisLenientsetFormattingStylesetHtmlSafesetIndentsetLenientsetSerializeNullssetStrictness

Field Detail

pendingNameback to summary
private String pendingName

The name for the next JSON object value. If non-null, the top of the stack is a JsonObject.

productback to summary
private JsonElement product

the JSON element constructed by this writer.

SENTINEL_CLOSEDback to summary
private static final JsonPrimitive SENTINEL_CLOSED

Added to the top of the stack when this writer is closed to cause following ops to fail.

stackback to summary
private final List<JsonElement> stack

Hides com.google.gson.stream.JsonWriter.stack.

The JsonElements and JsonArrays under modification, outermost to innermost.

UNWRITABLE_WRITERback to summary
private static final Writer UNWRITABLE_WRITER

Constructor Detail

JsonTreeWriterback to summary
public JsonTreeWriter()

Method Detail

beginArrayback to summary
public JsonWriter beginArray() throws IOException

Overrides com.google.gson.stream.JsonWriter.beginArray.

Doc from com.google.gson.stream.JsonWriter.beginArray.

Begins encoding a new array. Each call to this method must be paired with a call to endArray.

Annotations
@CanIgnoreReturnValue
@Override
beginObjectback to summary
public JsonWriter beginObject() throws IOException

Overrides com.google.gson.stream.JsonWriter.beginObject.

Doc from com.google.gson.stream.JsonWriter.beginObject.

Begins encoding a new object. Each call to this method must be paired with a call to endObject.

Annotations
@CanIgnoreReturnValue
@Override
closeback to summary
public void close() throws IOException

Overrides com.google.gson.stream.JsonWriter.close.

Implements java.io.Closeable.close.

Doc from com.google.gson.stream.JsonWriter.close.

Flushes and closes this writer and the underlying Writer.

Annotations
@Override
Exceptions
IOException:
if the JSON document is incomplete.
endArrayback to summary
public JsonWriter endArray() throws IOException

Overrides com.google.gson.stream.JsonWriter.endArray.

Doc from com.google.gson.stream.JsonWriter.endArray.

Ends encoding the current array.

Annotations
@CanIgnoreReturnValue
@Override
endObjectback to summary
public JsonWriter endObject() throws IOException

Overrides com.google.gson.stream.JsonWriter.endObject.

Doc from com.google.gson.stream.JsonWriter.endObject.

Ends encoding the current object.

Annotations
@CanIgnoreReturnValue
@Override
flushback to summary
public void flush() throws IOException

Overrides com.google.gson.stream.JsonWriter.flush.

Implements java.io.Flushable.flush.

Doc from com.google.gson.stream.JsonWriter.flush.

Ensures all buffered data is written to the underlying Writer and flushes that writer.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Flushable.flush.

If an I/O error occurs

getback to summary
public JsonElement get()

Returns the top level object produced by this writer.

jsonValueback to summary
public JsonWriter jsonValue(String value) throws IOException

Overrides com.google.gson.stream.JsonWriter.jsonValue.

Doc from com.google.gson.stream.JsonWriter.jsonValue.

Writes value directly to the writer without quoting or escaping. This might not be supported by all implementations, if not supported an UnsupportedOperationException is thrown.

Annotations
@Override
nameback to summary
public JsonWriter name(String name) throws IOException

Overrides com.google.gson.stream.JsonWriter.name.

Doc from com.google.gson.stream.JsonWriter.name.

Encodes the property name.

Annotations
@CanIgnoreReturnValue
@Override
nullValueback to summary
public JsonWriter nullValue() throws IOException

Overrides com.google.gson.stream.JsonWriter.nullValue.

Doc from com.google.gson.stream.JsonWriter.nullValue.

Encodes null.

Annotations
@CanIgnoreReturnValue
@Override
peekback to summary
private JsonElement peek()

Hides com.google.gson.stream.JsonWriter.peek.

Doc from com.google.gson.stream.JsonWriter.peek.

Returns the value on the top of the stack.

putback to summary
private void put(JsonElement value)
valueback to summary
public JsonWriter value(String value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value.

Annotations
@CanIgnoreReturnValue
@Override
valueback to summary
public JsonWriter value(boolean value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value.

Annotations
@CanIgnoreReturnValue
@Override
valueback to summary
public JsonWriter value(Boolean value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value.

Annotations
@CanIgnoreReturnValue
@Override
valueback to summary
public JsonWriter value(float value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value.

Annotations
@CanIgnoreReturnValue
@Override
valueback to summary
public JsonWriter value(double value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value.

Annotations
@CanIgnoreReturnValue
@Override
valueback to summary
public JsonWriter value(long value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value.

Annotations
@CanIgnoreReturnValue
@Override
valueback to summary
public JsonWriter value(Number value) throws IOException

Overrides com.google.gson.stream.JsonWriter.value.

Doc from com.google.gson.stream.JsonWriter.value.

Encodes value. The value is written by directly writing the Number#toString() result to JSON. Implementations must make sure that the result represents a valid JSON number.

Annotations
@CanIgnoreReturnValue
@Override