defaultNodeFromJson<T> function

Node<T> defaultNodeFromJson<T>(
  1. Map<String, dynamic> json,
  2. T fromJsonT(
    1. Object? json
    )
)

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 data
  • fromJsonT - Function to deserialize the custom data of type T

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),
  };
}