ReleaseDescriptor.fromJson constructor

ReleaseDescriptor.fromJson(
  1. Map<String, dynamic> json
)

Parses and validates a schema-v3 release descriptor from JSON.

Implementation

factory ReleaseDescriptor.fromJson(Map<String, dynamic> json) {
  final descriptor = ReleaseDescriptor(
    schemaVersion: json["schemaVersion"] as int? ?? 0,
    packageId: (json["packageId"] as String? ?? "").trim(),
    appName: json["appName"] as String? ?? "",
    version: (json["version"] as String? ?? "").trim(),
    buildNumber: json["buildNumber"] as int?,
    platform: (json["platform"] as String? ?? "").trim(),
    channel: (json["channel"] as String? ?? "stable").trim(),
    artifact: ReleaseArtifact.fromJson(
      json["artifact"] as Map<String, dynamic>? ?? const {},
    ),
    install: ReleaseInstall.fromJson(
      json["install"] as Map<String, dynamic>? ?? const {},
    ),
    minimumOS: _parseMinimumOS(json["minimumOS"]),
    deltaArtifacts: _parseDeltaArtifacts(json["deltaArtifacts"]),
    signature: json["signature"] == null
        ? null
        : ReleaseSignature.fromJson(
            json["signature"] as Map<String, dynamic>,
          ),
    minimumUpdaterVersion: json["minimumUpdaterVersion"] as String? ?? "",
    generatedAt: DateTime.parse(
      json["generatedAt"] as String? ?? "1970-01-01T00:00:00Z",
    ),
  )..validate();
  return descriptor;
}