fix: flexible int parsing in PlexRole

This commit is contained in:
edde746
2026-03-28 13:44:57 +01:00
parent 0bb200a785
commit 46ebda944a
2 changed files with 10 additions and 2 deletions
+8
View File
@@ -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});
+2 -2
View File
@@ -7,13 +7,13 @@ part of 'plex_role.dart';
// **************************************************************************
PlexRole _$PlexRoleFromJson(Map<String, dynamic> 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<String, dynamic> _$PlexRoleToJson(PlexRole instance) => <String, dynamic>{