You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
The documentation promises that in the future, YamlMap would just be a regular Map instead.
However, this future does not seem to have resolved as of yet, which is incredibly inconvenient for using fromJson methods with the decoded Yaml.
The return value is mostly normal Dart objects. However, since YAML mappings support some key types that the default Dart map implementation doesn't (NaN, lists, and maps), all maps in the returned document are YamlMaps. These have a few small behavioral differences from the default Map implementation; for details, see the YamlMap class.
In future versions, maps will instead be HashMaps with a custom equality operation.
For that reason, I have written a small method that undoes this mess:
/// Recreates all Maps and Lists recursively to ensure normal Dart typesdynamicyamlToDart(dynamic value) {
if (value isMap) {
List<MapEntry<String, dynamic>> entries = [];
// we cannot directly use `entries` because `YamlMap` will return Nodes instead of values.for (final key in value.keys) {
entries.add(MapEntry(key, yamlToDart(value[key])));
}
returnMap.fromEntries(entries);
} elseif (value isList) {
returnList.from(value.map(yamlToDart));
} else {
return value;
}
}
this is more of a hack than anything, but it should normalize your types.
why there is no simple way described, just to convert this YamlDocument into ordinary Map type?
The text was updated successfully, but these errors were encountered: