From 46ebda944aceb06a17185fd47f44f775a4677129 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sat, 28 Mar 2026 13:44:57 +0100 Subject: [PATCH] fix: flexible int parsing in PlexRole --- lib/models/plex_role.dart | 8 ++++++++ lib/models/plex_role.g.dart | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/models/plex_role.dart b/lib/models/plex_role.dart index daae1daf..f0aff798 100644 --- a/lib/models/plex_role.dart +++ b/lib/models/plex_role.dart @@ -2,14 +2,22 @@ import 'package:json_annotation/json_annotation.dart'; part 'plex_role.g.dart'; +int? _flexibleInt(Object? v) => switch (v) { + num n => n.toInt(), + String s => int.tryParse(s), + _ => null, + }; + @JsonSerializable() class PlexRole { + @JsonKey(fromJson: _flexibleInt) final int? id; final String? filter; final String tag; final String? tagKey; final String? role; final String? thumb; + @JsonKey(fromJson: _flexibleInt) final int? count; PlexRole({this.id, this.filter, required this.tag, this.tagKey, this.role, this.thumb, this.count}); diff --git a/lib/models/plex_role.g.dart b/lib/models/plex_role.g.dart index 52fa37b4..94294b9c 100644 --- a/lib/models/plex_role.g.dart +++ b/lib/models/plex_role.g.dart @@ -7,13 +7,13 @@ part of 'plex_role.dart'; // ************************************************************************** PlexRole _$PlexRoleFromJson(Map json) => PlexRole( - id: (json['id'] as num?)?.toInt(), + id: _flexibleInt(json['id']), filter: json['filter'] as String?, tag: json['tag'] as String, tagKey: json['tagKey'] as String?, role: json['role'] as String?, thumb: json['thumb'] as String?, - count: (json['count'] as num?)?.toInt(), + count: _flexibleInt(json['count']), ); Map _$PlexRoleToJson(PlexRole instance) => {