Files
plezy/lib/utils/json_utils.dart
T
2026-04-01 12:20:07 +02:00

10 lines
382 B
Dart

/// Parse a value that may be [int], [num], or [String] to [int].
/// Used as `@JsonKey(fromJson: flexibleInt)` and in manual `fromJson` factories
/// to handle Plex API responses where numeric fields may arrive as strings
/// (XML-to-JSON conversion).
int? flexibleInt(Object? v) => switch (v) {
num n => n.toInt(),
String s => int.tryParse(s),
_ => null,
};