Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable to json for every serializable model #213

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
497 changes: 497 additions & 0 deletions lib/src/models/_models.g.dart

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions lib/src/models/album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
part of '_models.dart';

/// Json representation of an album
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Album extends AlbumSimple {
Album();

factory Album.fromJson(Map<String, dynamic> json) => _$AlbumFromJson(json);

@override
Map<String, dynamic> toJson() => _$AlbumToJson(this);

/// The copyright statements of the album.
List<Copyright>? copyrights;

Expand All @@ -34,13 +37,15 @@ class Album extends AlbumSimple {
int? popularity;
}

@JsonSerializable(createToJson: false)
@JsonSerializable()
class AlbumSimple extends Object {
AlbumSimple();

factory AlbumSimple.fromJson(Map<String, dynamic> json) =>
_$AlbumSimpleFromJson(json);

Map<String, dynamic> toJson() => _$AlbumSimpleToJson(this);

/// Helper function that unwraps the items from the paging object.
static Iterable<TrackSimple> _extractTracksFromPage(dynamic json) {
if (json == null) {
Expand Down
9 changes: 7 additions & 2 deletions lib/src/models/artist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
part of '_models.dart';

/// Json representation of an artist
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Artist extends Object implements ArtistSimple {
Artist();

factory Artist.fromJson(Map<String, dynamic> json) => _$ArtistFromJson(json);

@override
Map<String, dynamic> toJson() => _$ArtistToJson(this);

/// Known external URLs for this artist.
@JsonKey(name: 'external_urls')
@override
Expand Down Expand Up @@ -56,13 +59,15 @@ class Artist extends Object implements ArtistSimple {
}

/// Json representation of a simplified artist
@JsonSerializable(createToJson: false)
@JsonSerializable()
class ArtistSimple extends Object {
ArtistSimple();

factory ArtistSimple.fromJson(Map<String, dynamic> json) =>
_$ArtistSimpleFromJson(json);

Map<String, dynamic> toJson() => _$ArtistSimpleToJson(this);

/// Known external URLs for this artist.
@JsonKey(name: 'external_urls')
ExternalUrls? externalUrls;
Expand Down
17 changes: 12 additions & 5 deletions lib/src/models/audio_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
part of '_models.dart';

/// JSON representation of a track's analysis information
@JsonSerializable(createToJson: false)
@JsonSerializable()
class AudioAnalysis extends Object {
AudioAnalysis();

factory AudioAnalysis.fromJson(Map<String, dynamic> json) =>
_$AudioAnalysisFromJson(json);

Map<String, dynamic> toJson() => _$AudioAnalysisToJson(this);

TrackAudioAnalysis? track;

List<TimeInterval>? bars;
Expand Down Expand Up @@ -86,13 +88,15 @@ abstract class _Section {
}

/// JSON representation of the track analysis summary
@JsonSerializable(createToJson: false)
@JsonSerializable()
class TrackAudioAnalysis extends _Section {
TrackAudioAnalysis();

factory TrackAudioAnalysis.fromJson(Map<String, dynamic> json) =>
_$TrackAudioAnalysisFromJson(json);

Map<String, dynamic> toJson() => _$TrackAudioAnalysisToJson(this);

/// The exact number of audio samples analyzed from this track.
/// See also [analysisSampleRate].
@JsonKey(name: 'num_samples', fromJson: convertToIntIfDoubleValue)
Expand Down Expand Up @@ -143,24 +147,26 @@ class TrackAudioAnalysis extends _Section {
}

/// JSON representation of track section in the analysis
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Section extends _Section {
Section();

factory Section.fromJson(Map<String, dynamic> json) =>
_$SectionFromJson(json);
Map<String, dynamic> toJson() => _$SectionToJson(this);

/// The starting point (in seconds) of the section.
double? start;
}

/// JSON representation of track segment in the analysis
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Segment extends Object {
Segment();

factory Segment.fromJson(Map<String, dynamic> json) =>
_$SegmentFromJson(json);
Map<String, dynamic> toJson() => _$SegmentToJson(this);

/// The starting point (in seconds) of the segment.
double? start;
Expand Down Expand Up @@ -215,12 +221,13 @@ class Segment extends Object {

/// JSON representation of a time interval inside [AudioAnalysis.bars],
/// [AudioAnalysis.beats] and [AudioAnalysis.tatums],
@JsonSerializable(createToJson: false)
@JsonSerializable()
class TimeInterval extends Object {
TimeInterval();

factory TimeInterval.fromJson(Map<String, dynamic> json) =>
_$TimeIntervalFromJson(json);
Map<String, dynamic> toJson() => _$TimeIntervalToJson(this);

/// The confidence, from `0.0` to `1.0`, of the reliability of the interval.
double? confidence;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/audio_feature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
part of '_models.dart';

/// Json representation of an audio feature
@JsonSerializable(createToJson: false)
@JsonSerializable()
class AudioFeature extends Object {
AudioFeature();

factory AudioFeature.fromJson(Map<String, dynamic> json) =>
_$AudioFeatureFromJson(json);

Map<String, dynamic> toJson() => _$AudioFeatureToJson(this);

/// A confidence measure from `0.0` to `1.0` of whether the track is acoustic.
/// `1.0` represents high confidence the track is acoustic.
double? acousticness;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/category.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
part of '_models.dart';

/// Json representation of a category
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Category extends Object {
Category();

factory Category.fromJson(Map<String, dynamic> json) =>
_$CategoryFromJson(json);

Map<String, dynamic> toJson() => _$CategoryToJson(this);

/// A link to the Web API endpoint returning full details of the category.
String? href;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/copyright.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
part of '_models.dart';

/// Json representation of copyright
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Copyright extends Object {
Copyright();

factory Copyright.fromJson(Map<String, dynamic> json) =>
_$CopyrightFromJson(json);

Map<String, dynamic> toJson() => _$CopyrightToJson(this);

/// The copyright text for this album.
String? text;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
part of '_models.dart';

/// Json representation of a device
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Device extends Object {
Device();

factory Device.fromJson(Map<String, dynamic> json) => _$DeviceFromJson(json);

Map<String, dynamic> toJson() => _$DeviceToJson(this);

/// The device ID. This may be `null`.
String? id;

Expand Down
9 changes: 7 additions & 2 deletions lib/src/models/episode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
part of '_models.dart';

/// Json representation of an episode
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Episode extends Object {
Episode();

Expand Down Expand Up @@ -75,15 +75,20 @@ class Episode extends Object {

factory Episode.fromJson(Map<String, dynamic> json) =>
_$EpisodeFromJson(json);

Map<String, dynamic> toJson() => _$EpisodeToJson(this);
}

/// Json representation of an episode with information about its show
@JsonSerializable(createToJson: false)
@JsonSerializable()
class EpisodeFull extends Episode {
EpisodeFull();

Show? show;

factory EpisodeFull.fromJson(Map<String, dynamic> json) =>
_$EpisodeFullFromJson(json);

@override
Map<String, dynamic> toJson() => _$EpisodeFullToJson(this);
}
4 changes: 3 additions & 1 deletion lib/src/models/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
part of '_models.dart';

/// Json representation of an API error
@JsonSerializable(createToJson: false)
@JsonSerializable()
class SpotifyError extends Object {
SpotifyError();

factory SpotifyError.fromJson(Map<String, dynamic> json) =>
_$SpotifyErrorFromJson(json);

Map<String, dynamic> toJson() => _$SpotifyErrorToJson(this);

/// The HTTP status code (also returned in the response header; see Response
/// Status Codes for more information).
@JsonKey(fromJson: convertToIntIfDoubleValue)
Expand Down
8 changes: 6 additions & 2 deletions lib/src/models/external_objects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
part of '_models.dart';

/// Json representation of an external url
@JsonSerializable(createToJson: false)
@JsonSerializable()
class ExternalUrls extends Object {
ExternalUrls();

factory ExternalUrls.fromJson(Map<String, dynamic> json) =>
_$ExternalUrlsFromJson(json);

Map<String, dynamic> toJson() => _$ExternalUrlsToJson(this);

/// The Spotify URL for the object.
String? spotify;
}

/// Json representation of an external id
@JsonSerializable(createToJson: false)
@JsonSerializable()
class ExternalIds extends Object {
ExternalIds();

factory ExternalIds.fromJson(Map<String, dynamic> json) =>
_$ExternalIdsFromJson(json);

Map<String, dynamic> toJson() => _$ExternalIdsToJson(this);

/// International Standard Recording Code
String? isrc;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/followers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
part of '_models.dart';

/// Json representation of followers
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Followers extends Object {
Followers();

factory Followers.fromJson(Map<String, dynamic> json) =>
_$FollowersFromJson(json);

Map<String, dynamic> toJson() => _$FollowersToJson(this);

/// A link to the Web API endpoint providing full details of the followers;
/// null if not available.
///
Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
part of '_models.dart';

/// Json representation of an image
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Image extends Object {
Image();

factory Image.fromJson(Map<String, dynamic> json) => _$ImageFromJson(json);

Map<String, dynamic> toJson() => _$ImageToJson(this);

/// The image height in pixels. If unknown: null or not returned.
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? height;
Expand Down
12 changes: 9 additions & 3 deletions lib/src/models/paging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ class BasePaging<T> extends Object {
}

/// Json representation of a page with offset information
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Paging<T> extends BasePaging<T> {
Paging();

factory Paging.fromJson(Map<String, dynamic> json) => _$PagingFromJson(json);

Map<String, dynamic> toJson() => _$PagingToJson(this);

/// The offset of the items returned (as set in the query or by default).
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? offset;
Expand All @@ -60,21 +62,25 @@ class Paging<T> extends BasePaging<T> {
}

/// Json representation of a page with cursor information
@JsonSerializable(createToJson: false)
@JsonSerializable()
class CursorPaging<T> extends BasePaging<T> {
CursorPaging();

factory CursorPaging.fromJson(Map<String, dynamic> json) =>
_$CursorPagingFromJson(json);

Map<String, dynamic> toJson() => _$CursorPagingToJson(this);

Cursor? cursors;
}

/// Json representation of a cursor
@JsonSerializable(createToJson: false)
@JsonSerializable()
class Cursor extends Object {
factory Cursor.fromJson(Map<String, dynamic> json) => _$CursorFromJson(json);

Map<String, dynamic> toJson() => _$CursorToJson(this);

Cursor();
String? after;
}
Loading
Loading