fix(plex): tolerate scalar schema drift
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../utils/json_utils.dart';
|
||||
import 'plex_home_user.dart';
|
||||
|
||||
part 'plex_home.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class PlexHome {
|
||||
@JsonKey(defaultValue: 0)
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
final int id;
|
||||
@JsonKey(defaultValue: '')
|
||||
@JsonKey(readValue: readStringField, defaultValue: '')
|
||||
final String name;
|
||||
@JsonKey(fromJson: flexibleInt)
|
||||
final int? guestUserID;
|
||||
@JsonKey(defaultValue: '')
|
||||
@JsonKey(readValue: readStringField, defaultValue: '')
|
||||
final String guestUserUUID;
|
||||
@JsonKey(defaultValue: false)
|
||||
@JsonKey(fromJson: flexibleBool)
|
||||
final bool guestEnabled;
|
||||
@JsonKey(defaultValue: false)
|
||||
@JsonKey(fromJson: flexibleBool)
|
||||
final bool subscription;
|
||||
@JsonKey(defaultValue: <PlexHomeUser>[])
|
||||
final List<PlexHomeUser> users;
|
||||
@@ -50,3 +52,5 @@ class PlexHome {
|
||||
|
||||
bool get hasMultipleUsers => users.length > 1;
|
||||
}
|
||||
|
||||
int _intOr0(Object? value) => flexibleInt(value) ?? 0;
|
||||
|
||||
@@ -7,12 +7,12 @@ part of 'plex_home.dart';
|
||||
// **************************************************************************
|
||||
|
||||
PlexHome _$PlexHomeFromJson(Map<String, dynamic> json) => PlexHome(
|
||||
id: (json['id'] as num?)?.toInt() ?? 0,
|
||||
name: json['name'] as String? ?? '',
|
||||
guestUserID: (json['guestUserID'] as num?)?.toInt(),
|
||||
guestUserUUID: json['guestUserUUID'] as String? ?? '',
|
||||
guestEnabled: json['guestEnabled'] as bool? ?? false,
|
||||
subscription: json['subscription'] as bool? ?? false,
|
||||
id: _intOr0(json['id']),
|
||||
name: readStringField(json, 'name') as String? ?? '',
|
||||
guestUserID: flexibleInt(json['guestUserID']),
|
||||
guestUserUUID: readStringField(json, 'guestUserUUID') as String? ?? '',
|
||||
guestEnabled: flexibleBool(json['guestEnabled']),
|
||||
subscription: flexibleBool(json['subscription']),
|
||||
users:
|
||||
(json['users'] as List<dynamic>?)
|
||||
?.map((e) => PlexHomeUser.fromJson(e as Map<String, dynamic>))
|
||||
|
||||
Reference in New Issue
Block a user