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
This writer creates a JsonElement.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe name for the next JSON object value.private JsonElementthe JSON element constructed by this writer.private static final JsonPrimitiveAdded to the top of the stack when this writer is closed to cause following ops to fail.private final List<JsonElement> The JsonElements and JsonArrays under modification, outermost to innermost.private static final Writer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBegins encoding a new array.Begins encoding a new object.voidclose()Flushes and closes this writer and the underlyingWriter.endArray()Ends encoding the current array.Ends encoding the current object.voidflush()Ensures all buffered data is written to the underlyingWriterand flushes that writer.get()Returns the top level object produced by this writer.Writesvaluedirectly to the writer without quoting or escaping.Encodes the property name.Encodesnull.private JsonElementpeek()private voidput(JsonElement value) value(boolean value) Encodesvalue.value(double value) Encodesvalue.value(float value) Encodesvalue.value(long value) Encodesvalue.Encodesvalue.Encodesvalue.Encodesvalue.Methods inherited from class com.google.gson.stream.JsonWriter
getSerializeNulls, isHtmlSafe, isLenient, setHtmlSafe, setIndent, setLenient, setSerializeNulls
-
Field Details
-
UNWRITABLE_WRITER
-
SENTINEL_CLOSED
Added to the top of the stack when this writer is closed to cause following ops to fail. -
stack
The JsonElements and JsonArrays under modification, outermost to innermost. -
pendingName
The name for the next JSON object value. If non-null, the top of the stack is a JsonObject. -
product
the JSON element constructed by this writer.
-
-
Constructor Details
-
JsonTreeWriter
public JsonTreeWriter()
-
-
Method Details
-
get
Returns the top level object produced by this writer. -
peek
-
put
-
beginArray
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:
IOException
-
endArray
Description copied from class:JsonWriterEnds encoding the current array.- Overrides:
endArrayin classJsonWriter- Returns:
- this writer.
- Throws:
IOException
-
beginObject
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:
IOException
-
endObject
Description copied from class:JsonWriterEnds encoding the current object.- Overrides:
endObjectin classJsonWriter- Returns:
- this writer.
- Throws:
IOException
-
name
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:
IOException
-
value
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:
IOException
-
jsonValue
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:
IOException
-
nullValue
Description copied from class:JsonWriterEncodesnull.- Overrides:
nullValuein classJsonWriter- Returns:
- this writer.
- Throws:
IOException
-
value
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Returns:
- this writer.
- Throws:
IOException
-
value
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Returns:
- this writer.
- Throws:
IOException
-
value
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value, or iflenient, alsoNaNorinfinity.- Returns:
- this writer.
- Throws:
IOException
-
value
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Parameters:
value- a finite value, or iflenient, alsoNaNorinfinity.- Returns:
- this writer.
- Throws:
IOException
-
value
Description copied from class:JsonWriterEncodesvalue.- Overrides:
valuein classJsonWriter- Returns:
- this writer.
- Throws:
IOException
-
value
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:
IOException
-
flush
Description copied from class:JsonWriterEnsures all buffered data is written to the underlyingWriterand flushes that writer.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classJsonWriter- Throws:
IOException
-
close
Description copied from class:JsonWriterFlushes and closes this writer and the underlyingWriter.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classJsonWriter- Throws:
IOException- if the JSON document is incomplete.
-