castValues method

void castValues(
  1. Map<String, Cast> schema
)

Typecast the values in this archive.

Prefer to override Coding.castMap instead of using this method directly.

This method will recursively type values in this archive to the desired type for a given key. Use this method (or Coding.castMap) for decoding List and Map types, where the values are not Coding objects.

You must import 'package:dynacode/cast.dart' as cast;.

Usage:

    final dynamicObject = {
      "key": <dynamic>["foo", "bar"]
    };
    final archive = KeyedArchive.unarchive(dynamicObject);
    archive.castValues({
      "key": cast.List(cast.String)
    });

    // This now becomes a valid assignment
    List<String> key = archive.decode("key");

Implementation

void castValues(Map<String, cast.Cast> schema) {
  final caster = new cast.Keyed(schema);
  _map = caster.customcast(_map, "toplevel", null);

  if (_objectReference != null) {
    // todo: can optimize this by only running it once
    _objectReference!._map =
        caster.customcast(_objectReference!._map, "toplevel", null);
  }
}