fromJson static method

TrackPublishedGetResponse? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static TrackPublishedGetResponse? 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 "TrackPublishedGetResponse[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "TrackPublishedGetResponse[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return TrackPublishedGetResponse(
      trackId: mapValueOfType<int>(json, r'TrackId'),
      title: mapValueOfType<String>(json, r'Title'),
      artist: mapValueOfType<String>(json, r'Artist'),
      album: mapValueOfType<String>(json, r'Album'),
      ownerId: mapValueOfType<int>(json, r'OwnerId'),
      ownerName: mapValueOfType<String>(json, r'OwnerName'),
      ownerContainer: mapValueOfType<String>(json, r'OwnerContainer'),
      name: mapValueOfType<String>(json, r'Name'),
      fileHash: mapValueOfType<String>(json, r'FileHash'),
      rating: mapValueOfType<double>(json, r'Rating'),
      audioFile: mapValueOfType<String>(json, r'AudioFile'),
      duration: mapValueOfType<String>(json, r'Duration'),
      imageFile: mapValueOfType<String>(json, r'ImageFile'),
      genreTracks: json[r'GenreTracks'] is List
          ? (json[r'GenreTracks'] as List).cast<String>()
          : const [],
    );
  }
  return null;
}