fromJson static method
Returns a native instance of an OpenAPI class matching the targetType
.
Implementation
static dynamic fromJson(
dynamic value,
String targetType, {
bool growable = false,
}) {
try {
switch (targetType) {
case 'String':
return value is String ? value : value.toString();
case 'int':
return value is int ? value : int.parse('$value');
case 'double':
return value is double ? value : double.parse('$value');
case 'bool':
if (value is bool) {
return value;
}
final valueString = '$value'.toLowerCase();
return valueString == 'true' || valueString == '1';
case 'DateTime':
return value is DateTime ? value : DateTime.tryParse(value);
case 'ActiveOrder':
return ActiveOrder.fromJson(value);
case 'Address':
return Address.fromJson(value);
case 'AnchorToken':
return AnchorToken.fromJson(value);
case 'AvailableState':
return AvailableState.fromJson(value);
case 'ChronicStats':
return ChronicStats.fromJson(value);
case 'CountryEnum':
return CountryEnumTypeTransformer().decode(value);
case 'Customer':
return Customer.fromJson(value);
case 'ErrorDescription':
return ErrorDescription.fromJson(value);
case 'FileUpload':
return FileUpload.fromJson(value);
case 'FileUploaded':
return FileUploaded.fromJson(value);
case 'FilterEventsEnum':
return FilterEventsEnumTypeTransformer().decode(value);
case 'GlobalStatistics':
return GlobalStatistics.fromJson(value);
case 'GlobalStatisticsGroupByEnum':
return GlobalStatisticsGroupByEnumTypeTransformer().decode(value);
case 'GoogleIdToken':
return GoogleIdToken.fromJson(value);
case 'HealthStatus':
return HealthStatus.fromJson(value);
case 'Membership':
return Membership.fromJson(value);
case 'Model':
return Model.fromJson(value);
case 'ModelCreate':
return ModelCreate.fromJson(value);
case 'ModelInfo':
return ModelInfo.fromJson(value);
case 'ModelStatus':
return ModelStatusTypeTransformer().decode(value);
case 'ModelUpdate':
return ModelUpdate.fromJson(value);
case 'NewSubscription':
return NewSubscription.fromJson(value);
case 'NewSubscriptionCreate':
return NewSubscriptionCreate.fromJson(value);
case 'Order':
return Order.fromJson(value);
case 'OrderComment':
return OrderComment.fromJson(value);
case 'OrderCommentCreate':
return OrderCommentCreate.fromJson(value);
case 'OrderCreate':
return OrderCreate.fromJson(value);
case 'OrderDetail':
return OrderDetail.fromJson(value);
case 'OrderModel':
return OrderModel.fromJson(value);
case 'OrderModelComment':
return OrderModelComment.fromJson(value);
case 'OrderModelCommentCreate':
return OrderModelCommentCreate.fromJson(value);
case 'OrderModelCreate':
return OrderModelCreate.fromJson(value);
case 'OrderModelDetail':
return OrderModelDetail.fromJson(value);
case 'OrderModelFile':
return OrderModelFile.fromJson(value);
case 'OrderModelUpdate':
return OrderModelUpdate.fromJson(value);
case 'OrderState':
return OrderStateTypeTransformer().decode(value);
case 'OrderUpdate':
return OrderUpdate.fromJson(value);
case 'PasswordChange':
return PasswordChange.fromJson(value);
case 'PasswordReset':
return PasswordReset.fromJson(value);
case 'PasswordResetConfirm':
return PasswordResetConfirm.fromJson(value);
case 'PatchedAddress':
return PatchedAddress.fromJson(value);
case 'PatchedModelUpdate':
return PatchedModelUpdate.fromJson(value);
case 'PatchedProjectUpdate':
return PatchedProjectUpdate.fromJson(value);
case 'PaymentMethodEnum':
return PaymentMethodEnumTypeTransformer().decode(value);
case 'PriceCurrencyEnum':
return PriceCurrencyEnumTypeTransformer().decode(value);
case 'PricingPlan':
return PricingPlan.fromJson(value);
case 'Project':
return Project.fromJson(value);
case 'ProjectCreate':
return ProjectCreate.fromJson(value);
case 'ProjectStatistics':
return ProjectStatistics.fromJson(value);
case 'ProjectStatisticsGroupByEnum':
return ProjectStatisticsGroupByEnumTypeTransformer().decode(value);
case 'ProjectUpdate':
return ProjectUpdate.fromJson(value);
case 'Registration':
return Registration.fromJson(value);
case 'RegistrationCreate':
return RegistrationCreate.fromJson(value);
case 'RoleEnum':
return RoleEnumTypeTransformer().decode(value);
case 'StateChanged':
return StateChanged.fromJson(value);
case 'Subscription':
return Subscription.fromJson(value);
case 'SummaryStats':
return SummaryStats.fromJson(value);
case 'TimeRangeEnum':
return TimeRangeEnumTypeTransformer().decode(value);
case 'TokenObtainRequest':
return TokenObtainRequest.fromJson(value);
case 'TokenObtainResponse':
return TokenObtainResponse.fromJson(value);
case 'TokenRefreshRequest':
return TokenRefreshRequest.fromJson(value);
case 'TokenRefreshResponse':
return TokenRefreshResponse.fromJson(value);
case 'TokenVerify':
return TokenVerify.fromJson(value);
case 'User':
return User.fromJson(value);
case 'UserVerified':
return UserVerified.fromJson(value);
default:
dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => fromJson(
v,
match,
growable: growable,
))
.toList(growable: growable);
}
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => fromJson(
v,
match,
growable: growable,
))
.toSet();
}
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(),
value.values.map<dynamic>((dynamic v) => fromJson(
v,
match,
growable: growable,
)),
);
}
}
} on Exception catch (error, trace) {
throw ApiException.withInner(
HttpStatus.internalServerError,
'Exception during deserialization.',
error,
trace,
);
}
throw ApiException(
HttpStatus.internalServerError,
'Could not find a suitable class for deserialization',
);
}