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 'Author':
return Author.fromJson(value);
case 'AuthorDetail':
return AuthorDetail.fromJson(value);
case 'DaiPoint':
return DaiPoint.fromJson(value);
case 'Dataset':
return Dataset.fromJson(value);
case 'DatasetDetail':
return DatasetDetail.fromJson(value);
case 'DeletionSummary':
return DeletionSummary.fromJson(value);
case 'DeletionSummaryTimelineInner':
return DeletionSummaryTimelineInner.fromJson(value);
case 'DeletionSummaryTopByDownloadsInner':
return DeletionSummaryTopByDownloadsInner.fromJson(value);
case 'DelistedModel':
return DelistedModel.fromJson(value);
case 'DownloadAnomaly':
return DownloadAnomaly.fromJson(value);
case 'DownloadPoint':
return DownloadPoint.fromJson(value);
case 'Envelope':
return Envelope.fromJson(value);
case 'Error':
return Error.fromJson(value);
case 'Event':
return Event.fromJson(value);
case 'GetAuthor200Response':
return GetAuthor200Response.fromJson(value);
case 'GetDataset200Response':
return GetDataset200Response.fromJson(value);
case 'GetHistoricalDeletionSummary200Response':
return GetHistoricalDeletionSummary200Response.fromJson(value);
case 'GetIndex200Response':
return GetIndex200Response.fromJson(value);
case 'GetMethod200Response':
return GetMethod200Response.fromJson(value);
case 'GetModel200Response':
return GetModel200Response.fromJson(value);
case 'GetModelDownloadHistory200Response':
return GetModelDownloadHistory200Response.fromJson(value);
case 'GetModelReadmeAt200Response':
return GetModelReadmeAt200Response.fromJson(value);
case 'HistoricalDeletion':
return HistoricalDeletion.fromJson(value);
case 'Index':
return Index.fromJson(value);
case 'IndexDetail':
return IndexDetail.fromJson(value);
case 'ListAnomalies200Response':
return ListAnomalies200Response.fromJson(value);
case 'ListAuthors200Response':
return ListAuthors200Response.fromJson(value);
case 'ListDatasets200Response':
return ListDatasets200Response.fromJson(value);
case 'ListDelistedModels200Response':
return ListDelistedModels200Response.fromJson(value);
case 'ListHistoricalDeletions200Response':
return ListHistoricalDeletions200Response.fromJson(value);
case 'ListIndices200Response':
return ListIndices200Response.fromJson(value);
case 'ListMethods200Response':
return ListMethods200Response.fromJson(value);
case 'ListModelReadmeDrifts200Response':
return ListModelReadmeDrifts200Response.fromJson(value);
case 'ListModels200Response':
return ListModels200Response.fromJson(value);
case 'ListTimeline200Response':
return ListTimeline200Response.fromJson(value);
case 'Method':
return Method.fromJson(value);
case 'MethodDetail':
return MethodDetail.fromJson(value);
case 'MethodDetailAllOfTopAuthors':
return MethodDetailAllOfTopAuthors.fromJson(value);
case 'ModelDetail':
return ModelDetail.fromJson(value);
case 'ModelSummary':
return ModelSummary.fromJson(value);
case 'Passport':
return Passport.fromJson(value);
case 'ReadmeAt':
return ReadmeAt.fromJson(value);
case 'ReadmeDrift':
return ReadmeDrift.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',);
}