CockpitCommandResult.fromJson constructor

CockpitCommandResult.fromJson(
  1. Map<String, Object?> json, {
  2. String path = r'$',
})

Decodes a CockpitCommandResult from a JSON object.

Implementation

factory CockpitCommandResult.fromJson(
  Map<String, Object?> json, {
  String path = r'$',
}) {
  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 surfaceJson = json['surface'] as Map<Object?, Object?>?;
  final appStateJson = json['appState'] as Map<Object?, Object?>?;
  final actionResultJson = json['actionResult'] 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'],
      path: '$path.commandType',
    ),
    locatorResolution: locatorResolutionJson == null
        ? null
        : CockpitLocatorResolution.fromJson(
            Map<String, Object?>.from(locatorResolutionJson),
            path: '$path.locatorResolution',
          ),
    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?,
    surface: surfaceJson == null
        ? null
        : Map<String, Object?>.from(surfaceJson),
    appState: appStateJson == null
        ? null
        : Map<String, Object?>.from(appStateJson),
    actionResult: actionResultJson == null
        ? null
        : Map<String, Object?>.from(actionResultJson),
    changed: json['changed'] as bool?,
    error: errorJson == null
        ? null
        : CockpitCommandError.fromJson(Map<String, Object?>.from(errorJson)),
  );
}