CockpitContextBundle.fromJson constructor

CockpitContextBundle.fromJson(
  1. Map<String, Object?> json
)

Decodes a CockpitContextBundle from a JSON object.

Implementation

factory CockpitContextBundle.fromJson(Map<String, Object?> json) {
  final manifestJson = Map<String, Object?>.from(
    json['manifest']! as Map<Object?, Object?>,
  );
  final environmentJson = Map<String, Object?>.from(
    json['environment']! as Map<Object?, Object?>,
  );
  final stepJson = (json['steps'] as List<Object?>? ?? const <Object?>[])
      .cast<Map<Object?, Object?>>();
  final observationJson =
      (json['observations'] as List<Object?>? ?? const <Object?>[])
          .cast<Map<Object?, Object?>>();

  return CockpitContextBundle(
    manifest: CockpitRunManifest.fromJson(manifestJson),
    environment: CockpitEnvironment.fromJson(environmentJson),
    steps: stepJson
        .map(
          (item) =>
              CockpitStepRecord.fromJson(Map<String, Object?>.from(item)),
        )
        .toList(),
    observations: observationJson
        .map(
          (item) =>
              CockpitObservation.fromJson(Map<String, Object?>.from(item)),
        )
        .toList(),
    acceptanceMarkdown: json['acceptanceMarkdown']! as String,
    handoff: Map<String, Object?>.from(
      (json['handoff'] as Map<Object?, Object?>?) ??
          const <Object?, Object?>{},
    ),
    delivery: Map<String, Object?>.from(
      (json['delivery'] as Map<Object?, Object?>?) ??
          const <Object?, Object?>{},
    ),
  );
}