deserialize static method

dynamic deserialize(
  1. dynamic value,
  2. String targetType
)

Implementation

static dynamic deserialize(dynamic value, String targetType) {
  if (value == null) return null; // 204
  try {
    switch (targetType) {
      case 'String':
        return '$value';
      case 'int':
        return value is int ? value : int.parse('$value');
      case 'bool':
        return value is bool ? value : '$value'.toLowerCase() == 'true';
      case 'double':
        return value is double ? value : double.parse('$value');
      case 'ApplicationVersionInfo':
        return ApplicationVersionInfo.fromJson(value);
      case 'BaseRolloutStrategy':
        return BaseRolloutStrategy.fromJson(value);
      case 'BaseRolloutStrategyAttribute':
        return BaseRolloutStrategyAttribute.fromJson(value);
      case 'FeatureEnvironmentCollection':
        return FeatureEnvironmentCollection.fromJson(value);
      case 'FeatureRolloutStrategy':
        return FeatureRolloutStrategy.fromJson(value);
      case 'FeatureRolloutStrategyAttribute':
        return FeatureRolloutStrategyAttribute.fromJson(value);
      case 'FeatureState':
        return FeatureState.fromJson(value);
      case 'FeatureStateUpdate':
        return FeatureStateUpdate.fromJson(value);
      case 'FeatureValueType':
        return FeatureValueTypeExtension.fromJson(value);
      case 'RoleType':
        return RoleTypeExtension.fromJson(value);
      case 'RolloutStrategyAttributeConditional':
        return RolloutStrategyAttributeConditionalExtension.fromJson(value);
      case 'RolloutStrategyFieldType':
        return RolloutStrategyFieldTypeExtension.fromJson(value);
      case 'SSEResultState':
        return SSEResultStateExtension.fromJson(value);
      case 'StrategyAttributeCountryName':
        return StrategyAttributeCountryNameExtension.fromJson(value);
      case 'StrategyAttributeDeviceName':
        return StrategyAttributeDeviceNameExtension.fromJson(value);
      case 'StrategyAttributePlatformName':
        return StrategyAttributePlatformNameExtension.fromJson(value);
      case 'StrategyAttributeWellKnownNames':
        return StrategyAttributeWellKnownNamesExtension.fromJson(value);
      default:
        return matchLeftovers(value, targetType, (v, t) => deserialize(v, t));
    }
  } on Exception catch (e, stack) {
    throw ApiException.withInner(
        500, 'Exception during deserialization.', e, stack);
  }
}