MapAdapter<K, V> class

A TypeAdapter that adapts a raw Object into a strongly typed Map of type K, V.

Jetleaf’s conversion service may return Map<Object, Object> or HashMap, which may represent key-value pairs. This adapter ensures that the raw input is converted into a Dart Map<K, V>.

  • If source is null, an empty map is returned.
  • If source is a Map, it is directly converted using Map<K, V>.from.
  • If source is a HashMap, entries are iterated and retyped.
  • Otherwise, an IllegalArgumentException is thrown.

Example

final adapter = MapAdapter<String, int>();
final map = adapter.adapt({'a': 1, 'b': 2}); // {a: 1, b: 2}

final rawHashMap = HashMap()
  ..['x'] = 10
  ..['y'] = 20;
final adapted = adapter.adapt(rawHashMap); // {x: 10, y: 20}

final empty = adapter.adapt(null); // {}
Implemented types
Annotations
  • @Generic.new(MapAdapter)

Constructors

MapAdapter()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

adapt(Object? source) Map<K, V>
A Jetleaf-specific adapter that lifts generic conversion results into strongly-typed values.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited