Dumping Mapping topic
Dumps any Map-like objects. The default scalar style is ScalarStyle.plain (you can override this).
Note
From version 0.3.1 and below keys and values could have different scalar styles. In the current version, both keys and values with use the same scalar style. Future changes may allow granular customisation of this behaviour.
Flow Mappings
Flow mappings start with { and terminate with }. All entries are always dumped on a new line.
Implicit keys
Inline keys are dumped as implicit keys.
dumpObject(
{'key': 'value'},
dumper: ObjectDumper.of(mapStyle: NodeStyle.flow),
);
# Output in yaml
{
"key": "value"
}
Explicit keys
Collections or multiline scalars are encoded with an explicit key.
dumpObject(
{{'key': 'value'} : {'key': 'value'}},
dumper: ObjectDumper.of(mapStyle: NodeStyle.flow),
);
# Output in yaml
{
? {
"key": "value"
}
: {
"key": "value"
}
}
Inlined flow maps
You can always inline flow maps. This is quite handy since some flow nodes can act as implicit keys as long as they do not exceed the 1024 unicode-count-limit.
dumpObject(
{{'key': 'value'} : {'key': 'value'}},
dumper: ObjectDumper.of(mapStyle: NodeStyle.flow, forceMapsInline: true),
);
# Output in yaml
{{key: value}: {key: value}}
Block Mappings
Block mapping have no explicit starting or terminating indicators.
Explicit keys
Block mappings have a low threshold for explicit keys. Keys are encoded as explicit keys if:
- The
keyScalarStyleis a block scalar style (literalorfolded) or isnull. - The scalar is spans multiple line.
- The key is a collection (
MaporIterable).
dumpObject(
{['block', 'list']: 'value' },
dumper: ObjectDumper.of(
mapStyle: NodeStyle.block,
iterableStyle: NodeStyle.block,
),
);
# Output in yaml
? - block
- list
: value
Implicit keys
Only inline flow scalars/collections are dumped as implicit keys.
dumpObject(
{
['flow', 'list']: 'value',
'next': 'entry',
},
dumper: ObjectDumper.of(
mapStyle: NodeStyle.block,
iterableStyle: NodeStyle.flow,
forceIterablesInline: true,
),
);
# Output in yaml
[flow, list]: value
next: entry
Classes
- MapDumper Dumping Mapping
- A dumper for a Map.
- ObjectDumper Dumping Scalars Dumping Sequence Dumping Mapping
- A class used to dump objects.
Functions
-
dumpObject(
Object? object, {required YamlDumper dumper, int indent = 0, bool includeYamlDirective = false, Iterable< Dumping Scalars Dumping Sequence Dumping Mapping Dumping Types Dumping YAML DocumentsDirective> ? directives, OnProperties? objectProperties, bool includeGlobalTags = true, bool includeDocumendEnd = false}) → String -
Dumps an
objectwith the specifiedindent. Uses thedumperprovided.