CockpitCommandResult.fromJson constructor

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

Decodes a CockpitCommandResult from a JSON object.

Implementation

factory CockpitCommandResult.fromJson(Map<String, Object?> json) {
  final locatorResolutionJson =
      json['locatorResolution'] as Map<Object?, Object?>?;
  final errorJson = json['error'] as Map<Object?, Object?>?;
  final snapshotJson = json['snapshot'] as Map<Object?, Object?>?;
  final requestedCaptureProfile = json['requestedCaptureProfile'];
  final resolvedCaptureKind = json['resolvedCaptureKind'];

  return CockpitCommandResult(
    success: json['success']! as bool,
    commandId: json['commandId']! as String,
    commandType: CockpitCommandType.fromJson(json['commandType']),
    locatorResolution: locatorResolutionJson == null
        ? null
        : CockpitLocatorResolution.fromJson(
            Map<String, Object?>.from(locatorResolutionJson),
          ),
    durationMs: json['durationMs']! as int,
    artifacts: (json['artifacts'] as List<Object?>? ?? const <Object?>[])
        .cast<Map<Object?, Object?>>()
        .map(
          (item) =>
              CockpitArtifactRef.fromJson(Map<String, Object?>.from(item)),
        )
        .toList(growable: false),
    snapshot: snapshotJson == null
        ? null
        : Map<String, Object?>.from(snapshotJson),
    requestedCaptureProfile: requestedCaptureProfile == null
        ? null
        : CockpitCaptureProfile.fromJson(requestedCaptureProfile),
    resolvedCaptureKind: resolvedCaptureKind == null
        ? null
        : CockpitCaptureKind.fromJson(resolvedCaptureKind),
    usedCaptureFallback: json['usedCaptureFallback'] as bool? ?? false,
    degradationReason: json['degradationReason'] as String?,
    changed: json['changed'] as bool?,
    error: errorJson == null
        ? null
        : CockpitCommandError.fromJson(Map<String, Object?>.from(errorJson)),
  );
}