fix: flexible int parsing in PlexRole
This commit is contained in:
@@ -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});
|
||||
|
||||
@@ -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>{
|
||||
|
||||
Reference in New Issue
Block a user