fromJson static method

TrackIndexResponseData? fromJson(
  1. dynamic value
)

Returns a new TrackIndexResponseData instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static TrackIndexResponseData? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "TrackIndexResponseData[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "TrackIndexResponseData[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return TrackIndexResponseData(
      trackId: mapValueOfType<int>(json, r'TrackId'),
      name: mapValueOfType<String>(json, r'Name'),
      title: mapValueOfType<String>(json, r'Title'),
      album: mapValueOfType<String>(json, r'Album'),
      status: TrackStatus.fromJson(json[r'Status']),
      artist: mapValueOfType<String>(json, r'Artist'),
      isrc: mapValueOfType<String>(json, r'Isrc'),
      year: mapValueOfType<String>(json, r'Year'),
      audioFile: mapValueOfType<String>(json, r'AudioFile'),
      duration: SelectionDuration.fromJson(json[r'Duration']),
      ownerId: mapValueOfType<int>(json, r'OwnerId'),
      ownerName: mapValueOfType<String>(json, r'OwnerName'),
      ownerContainer: mapValueOfType<String>(json, r'OwnerContainer'),
      rating: mapValueOfType<double>(json, r'Rating'),
      publication: mapValueOfType<bool>(json, r'Publication'),
      cancel: mapValueOfType<bool>(json, r'Cancel'),
      cancelDate: mapDateTime(json, r'CancelDate', ''),
      fileHash: mapValueOfType<String>(json, r'FileHash'),
      createDate: mapDateTime(json, r'CreateDate', ''),
      companyTypeTracks: json[r'CompanyTypeTracks'] is List
          ? (json[r'CompanyTypeTracks'] as List).cast<String>()
          : const [],
      genreTracks: json[r'GenreTracks'] is List
          ? (json[r'GenreTracks'] as List).cast<String>()
          : const [],
      genreTracksString: mapValueOfType<String>(json, r'GenreTracksString'),
      imageFile: mapValueOfType<String>(json, r'ImageFile'),
    );
  }
  return null;
}