toJson method

Map<String, dynamic> toJson(
  1. Object? toJsonC(
    1. C value
    )
)

Converts this Connection to a JSON map.

This method serializes all connection properties, including observable values, to a JSON-compatible map.

Parameters

  • toJsonC: A function to serialize the typed data field. Pass (value) => value for simple types, or your type's toJson for complex types.

Example

// With typed data
final json = connection.toJson((data) => data?.toJson());

// Without typed data
final json = simpleConn.toJson((data) => null);

Implementation

Map<String, dynamic> toJson(Object? Function(C value) toJsonC) {
  final json = _$ConnectionToJson(this, toJsonC);
  // Include observable labels in JSON
  if (_startLabel.value != null) {
    json['startLabel'] = _startLabel.value!.toJson();
  }
  if (_label.value != null) {
    json['label'] = _label.value!.toJson();
  }
  if (_endLabel.value != null) {
    json['endLabel'] = _endLabel.value!.toJson();
  }
  return json;
}