deserialize static method
dynamic
deserialize(
- dynamic value,
- 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 'Environment':
return Environment.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 'RolloutStrategy':
return RolloutStrategy.fromJson(value);
case 'RolloutStrategyAttribute':
return RolloutStrategyAttribute.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);
}
}