-
Notifications
You must be signed in to change notification settings - Fork 34
Nested Lists
Maksym Koshovyi edited this page Oct 23, 2019
·
6 revisions
Jaguar handles nested Lists out-of-the-box.
import 'package:jaguar_serializer/jaguar_serializer.dart';
/// A serialized model used in [NestedList] and [NestedMap]
class Leaf {
String color;
Leaf({this.color});
bool operator ==(other) {
if (other is Leaf) return color == other.color;
return false;
}
int get hashCode => color?.hashCode;
}
class NestedList {
/// Tests nested list of built-ins
List<List<String>> strings;
/// Tests nested list of processor fields
List<List<DateTime>> dates;
/// Tests nested list of serialized objects
List<List<Leaf>> leafs;
NestedList({this.strings, this.dates, this.leafs});
int get hashCode => 0;
}
@GenSerializer()
class LeafSerializer extends Serializer<Leaf> with _$LeafSerializer {}
// DateTimeProcessor and other processors located in field_processor.dart
@GenSerializer(fields: const {"dates": const Field(processor: const DateTimeProcessor())})
class NestedListSerializer extends Serializer<NestedList>
with _$NestedListSerializer {}
Notice how Jaguar uses FieldProcessor
configured through processor
and Serializer
auto-detected or configured through serializers
. Pretty convenient, eh?