A format-specific Generator for producing YAML output.
The YamlGenerator defines the primitive write operations needed to serialize Dart objects into valid YAML. Higher-level serializers—such as Jetson’s reflection-based object serializers—use this interface to emit structured YAML without depending on any particular YAML library.
YAML requires indentation-based structure, mappings, sequences, scalar values, and key/value formatting. This interface abstracts those operations so Jetson serializers can remain format-agnostic.
Responsibilities
- Emit YAML mappings (objects) and sequences (lists)
- Write scalar values such as strings, numbers, booleans, and null
- Ensure proper key/value ordering and structural correctness
- Delegate indentation, formatting, and style rules to the concrete implementation (e.g., block vs. flow styles)
Notes
- Implementations may write to memory, streams, or files
- Indentation handling is implementation-defined
- Not all YAML styles (e.g., flow mappings) must be supported
Example (conceptual)
generator.writeStartMapping();
generator.writeKey('name');
generator.writeString('Alice');
generator.writeKey('roles');
generator.writeStartSequence();
generator.writeString('admin');
generator.writeString('editor');
generator.writeEndSequence();
generator.writeEndMapping();
print(generator.toString());
Which might produce:
name: "Alice"
roles:
- "admin"
- "editor"
See also
- Generator — base abstraction for all format generators
- YAML serializers using this generator
- Jetson’s object serialization pipeline
- 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 scalar value.
-
writeEndMapping(
) → void - Closes the current YAML mapping.
-
writeEndSequence(
) → void - Ends the current YAML sequence.
-
writeKey(
String key) → void - Writes a mapping key for a YAML object.
-
writeNull(
) → void -
Writes a null value, typically rendered as
nullin YAML. -
writeNumber(
num value) → void - Writes a numeric scalar value.
-
writeStartMapping(
) → void - Begins a new YAML mapping (equivalent to an object or dictionary).
-
writeStartSequence(
) → void - Begins a YAML sequence (list).
-
writeString(
String value) → void -
Writes a string value.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
CLASS
→ Class<
YamlGenerator> -
Represents the YamlGenerator type for reflection and dynamic resolution.
final