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() = "Bob";
    final archive = KeyedArchive.archive(person);
    final json = json.encode(archive);


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


keys → Iterable<String>
The keys of this. [...]
referenceURI ↔ Uri
A reference to another object in the same document. [...]
read / write
entries → Iterable<MapEntry<String, dynamic>>
The map entries of this.
read-only, inherited
hashCode → int
The hash code for this object.
read-only, inherited
isEmpty → bool
Returns true if there is no key/value pair in the map.
read-only, inherited
isNotEmpty → bool
Returns true if there is at least one key/value pair in the map.
read-only, inherited
length → int
The number of key/value pairs in the map.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited
values → Iterable
The values of this.
read-only, inherited


castValues(Map<String, Cast> schema) → void
Typecast the values in this archive. [...]
clear() → void
Removes all pairs from the map. [...]
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. [...]
remove(Object key) → dynamic
Removes key and its associated value, if present, from the map. [...]
resolveOrThrow(ReferenceResolver coder) → void
Validates referenceURIs for this object and any objects it contains. [...]
toPrimitive() → Map<String, dynamic>
addAll(Map<String, dynamic> other) → void
Adds all key/value pairs of other to this map.
addEntries(Iterable<MapEntry<String, dynamic>> newEntries) → void
Adds all key/value pairs of newEntries to this map.
cast<RK, RV>() → Map<RK, RV>
Provides a view of this map as having RK keys and RV instances, if necessary.
containsKey(Object key) → bool
Returns true if this map contains the given key.
containsValue(Object value) → bool
Returns true if this map contains the given value.
forEach(void action(K key, V value)) → void
Applies f to each key/value pair of the map.
map<K2, V2>(MapEntry<K2, V2> transform(K key, V value)) → Map<K2, V2>
Returns a new map where all entries of this map are transformed by the given f function.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
putIfAbsent(String key, dynamic ifAbsent()) → dynamic
Look up the value of key, or add a new value if it isn't there.
removeWhere(bool test(K key, V value)) → void
Removes all entries of this map that satisfy the given predicate.
toString() → String
Returns a string representation of this object.
update(String key, dynamic update(V value), { dynamic ifAbsent() }) → dynamic
Updates the value for the provided key.
updateAll(dynamic update(K key, V value)) → void
Updates all values.


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

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. [...]