KeyedArchive class

A container for a dynamic data object that can be decoded into Coding objects.

A KeyedArchive is a Map, but it provides additional behavior for decoding Coding objects and managing JSON Schema references ($ref) through methods like decode, decodeObject, etc.

You create a KeyedArchive by invoking KeyedArchive.unarchive and passing data decoded from a serialization format like JSON and YAML. A KeyedArchive is then provided as an argument to a Coding subclass' Coding.decode method.

    final json = json.decode(...);
    final archive = KeyedArchive.unarchive(json);
    final person = Person()..decode(archive);

You may also create KeyedArchives from Coding objects so that they can be serialized.

    final person = Person()..name = "Bob";
    final archive = KeyedArchive.archive(person);
    final json = json.encode(archive);
Mixed-in types

Constructors

KeyedArchive(Map<String, dynamic> _map)
Use unarchive instead.

Properties

entries Iterable<MapEntry<String, dynamic>>
The map entries of this Map.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether there is no key/value pair in the map.
no setterinherited
isNotEmpty bool
Whether there is at least one key/value pair in the map.
no setterinherited
keys Iterable<String>
The keys of this Map.
no setteroverride
length int
The number of key/value pairs in the map.
no setterinherited
referenceURI Uri?
A reference to another object in the same document.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
values Iterable
The values of this Map.
no setterinherited

Methods

addAll(Map<String, dynamic> other) → void
Adds all key/value pairs of other to this map.
inherited
addEntries(Iterable<MapEntry<String, dynamic>> newEntries) → void
Adds all key/value pairs of newEntries to this map.
inherited
cast<RK, RV>() Map<RK, RV>
Provides a view of this map as having RK keys and RV instances, if necessary.
inherited
castValues(Map<String, Cast>? schema) → void
Typecast the values in this archive.
clear() → void
Removes all entries from the map.
override
containsKey(Object? key) bool
Whether this map contains the given key.
inherited
containsValue(Object? value) bool
Whether this map contains the given value.
inherited
decode<T>(String? key) → T?
Returns the object associated by key.
decodeObject<T extends Coding>(String? key, T inflate()) → T?
Returns the instance of T associated with key.
decodeObjectMap<T extends Coding>(String? key, T inflate()) Map<String, T?>?
Returns a map of Ts associated with key.
decodeObjects<T extends Coding>(String key, T inflate()) List<T?>?
Returns a list of Ts associated with key.
encode(String key, dynamic value) → void
Encodes value into this object for key.
encodeObject(String key, Coding? value) → void
Encodes a Coding object into this object for key.
encodeObjectMap<T extends Coding>(String key, Map<String, T?>? value) → void
Encodes map of Coding objects into this object for key.
encodeObjects(String key, List<Coding?>? value) → void
Encodes list of Coding objects into this object for key.
forEach(void action(String key, dynamic value)) → void
Applies action to each key/value pair of the map.
inherited
map<K2, V2>(MapEntry<K2, V2> transform(String key, dynamic value)) Map<K2, V2>
Returns a new map where all entries of this map are transformed by the given convert function.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
putIfAbsent(String key, dynamic ifAbsent()) → dynamic
Look up the value of key, or add a new entry if it isn't there.
inherited
remove(Object? key) → dynamic
Removes key and its associated value, if present, from the map.
override
removeWhere(bool test(String key, dynamic value)) → void
Removes all entries of this map that satisfy the given test.
inherited
resolveOrThrow(ReferenceResolver coder) → void
Validates referenceURIs for this object and any objects it contains.
toPrimitive() Map<String, dynamic>
toString() String
A string representation of this object.
inherited
update(String key, dynamic update(dynamic value), {dynamic ifAbsent()?}) → dynamic
Updates the value for the provided key.
inherited
updateAll(dynamic update(String key, dynamic value)) → void
Updates all values.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](Object? key) → dynamic
The value for the given key, or null if key is not in the map.
override
operator []=(String key, dynamic value) → void
Associates the key with the given value.
override

Static Methods

archive(Coding root, {bool allowReferences = false}) Map<String, dynamic>
Archives a Coding object into a Map that can be serialized into format like JSON or YAML.
unarchive(Map<String, dynamic> data, {bool allowReferences = false}) KeyedArchive
Unarchives data into a KeyedArchive that can be used by Coding.decode to deserialize objects.