canDecode method

bool canDecode(
  1. Map<String, dynamic> value
)
inherited

Implementation

bool canDecode(Map<String, dynamic> value) {
  var discriminator = discriminatorValue;
  if (identical(discriminator, MappingFlags.useAsDefault)) {
    return true;
  } else if (discriminator is Function) {
    if (discriminator is bool Function(Map<String, dynamic>)) {
      return discriminator(value);
    } else {
      throw AssertionError(
          'Discriminator function must be of type "bool Function(Map<String, dynamic>)".');
    }
  } else if (discriminator == value[discriminatorKey]) {
    return true;
  }

  if (_subMappers.isNotEmpty) {
    for (var m in _subMappers) {
      if (m.discriminatorKey == discriminatorKey && m.canDecode(value)) {
        return true;
      }
    }
  }
  if (_defaultSubMapper != null &&
      _defaultSubMapper!.discriminatorKey == discriminatorKey) {
    return true;
  }

  return false;
}