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:

  1. The keyScalarStyle is a block scalar style (literal or folded) or is null.
  2. The scalar is spans multiple line.
  3. The key is a collection (Map or Iterable).
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<Directive>? directives, OnProperties? objectProperties, bool includeGlobalTags = true, bool includeDocumendEnd = false}) String Dumping Scalars Dumping Sequence Dumping Mapping Dumping Types Dumping YAML Documents
Dumps an object with the specified indent. Uses the dumper provided.