import 'package:rss_dart/dart_rss.dart'; extension WebFeedJson on WebFeed { Map toJson() { return { 'title': title, 'description': description, 'links': links.where((link) => link != null).toList(), 'items': items.map((item) => item.toJson()).toList(), }; } static WebFeed fromJson(Map json) { return WebFeed( title: json['title'] as String, description: json['description'] as String, links: (json['links'] as List).cast(), items: (json['items'] as List) .map((item) => WebFeedItemJson.fromJson(item as Map)) .toList(), ); } } extension WebFeedItemJson on WebFeedItem { Map toJson() { return { 'title': title, 'body': body, 'links': links.where((link) => link != null).toList(), 'updated': updated?.toIso8601String(), }; } static WebFeedItem fromJson(Map json) { return WebFeedItem( title: json['title'] as String, body: json['body'] as String, links: (json['links'] as List).cast(), updated: json['updated'] != null ? DateTime.parse(json['updated'] as String) : null, ); } }