getFromJsonToGenericFn function

dynamic getFromJsonToGenericFn(
  1. Map<List<String>, dynamic Function(Map<String, dynamic>)> fns,
  2. Map<String, dynamic> json,
  3. List<String> genericType
)

Resolves the matching fromJson function for the provided generic type ids.

Implementation

dynamic getFromJsonToGenericFn(
  Map<List<String>, dynamic Function(Map<String, dynamic>)> fns,
  Map<String, dynamic> json,
  List<String> genericType,
) {
  var types = genericType.map((e) => json[e]).toList();

  var fromJsonToGeneric_fn = fns.entries
      .firstWhereOrNull((entry) => ListEquality().equals(entry.key, types))
      ?.value;
  if (fromJsonToGeneric_fn == null) //
    throw Exception("From JSON function not found");
  return fromJsonToGeneric_fn;
}