matchLeftovers function

dynamic matchLeftovers(
  1. dynamic value,
  2. String targetType,
  3. Deserializer deserialize
)

Implementation

dynamic matchLeftovers(
    dynamic value, String targetType, Deserializer deserialize) {
  Match? match;

  if (value is List) {
    match = _regList.firstMatch(targetType);
    if (match != null) {
      final tt = match[1];

      if (tt != null) {
        return value.map((v) => deserialize(v, tt)).toList();
      }
    }
  }

  if (value is Map) {
    match = _regMap.firstMatch(targetType);
    if (match != null) {
      final tt = match[1];

      if (tt != null) {
        return Map.fromIterables(
            value.keys, value.values.map((v) => deserialize(v, tt)));
      }
    }
  }

  throw ApiException(
      500, 'Could not find a suitable class for deserialization');
}