A streaming JSON writer that outputs JSON tokens sequentially.
The JsonGenerator provides structured, incremental JSON output for JetLeaf’s serialization engine. It supports object and array boundaries, primitive values, and raw JSON injection for custom serialization cases.
Overview
- Produces syntactically valid JSON documents
- Supports streaming or in-memory output
- Typically used by ObjectMapper and custom serializers
Example
final generator = StringJsonGenerator();
generator.writeStartObject();
generator.writeFieldName('name');
generator.writeString('Alice');
generator.writeFieldName('age');
generator.writeNumber(30);
generator.writeEndObject();
print(generator.toString());
// Output: {"name":"Alice","age":30}
See also
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → FutureOr< void> -
Closes this resource, relinquishing any underlying resources.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
writeBoolean(
bool value) → void - Writes a boolean value.
-
writeEndArray(
) → void -
Writes the end of a JSON array (
]). -
writeEndObject(
) → void -
Writes the end of the current JSON object (
}). -
writeFieldName(
String name) → void - Writes a field name within an object context.
-
writeNull(
) → void - Writes a null literal.
-
writeNumber(
num value) → void - Writes a numeric value.
-
writeRaw(
String json) → void - Writes a raw JSON fragment directly to output.
-
writeStartArray(
) → void -
Writes the start of a JSON array (
[). -
writeStartObject(
) → void -
Writes the start of a JSON object (
{). -
writeString(
String value) → void -
Writes a string value.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
CLASS
→ Class<
JsonGenerator> -
Represents the JsonGenerator type for reflection and dynamic discovery.
final