defaultNodeFromJson<T> function
Default factory for deserializing nodes with type routing.
Routes to the appropriate Node subclass based on the 'type' field:
- 'group' -> GroupNode
- 'comment' -> CommentNode
- All other types -> Node (base class)
Parameters:
json- The JSON map containing node datafromJsonT- Function to deserialize the custom data of typeT
Implementation
Node<T> defaultNodeFromJson<T>(
Map<String, dynamic> json,
T Function(Object? json) fromJsonT,
) {
final type = json['type'] as String;
return switch (type) {
'group' => GroupNode.fromJsonMap<T>(json, fromJsonT),
'comment' => CommentNode.fromJsonMap<T>(json, fromJsonT),
_ => Node<T>.fromJson(json, fromJsonT),
};
}