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
isnull
, an empty map is returned. - If
source
is aMap
, it is directly converted usingMap<K, V>.from
. - If
source
is aHashMap
, 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
-
- TypeAdapter<
Map< K, V> >
- TypeAdapter<
- Annotations
-
- @Generic.new(MapAdapter)
Constructors
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