fromJson static method

Credential? fromJson(
  1. dynamic value
)

Returns a new Credential instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static Credential? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "Credential[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "Credential[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return Credential(
      id: mapValueOfType<int>(json, r'id')!,
      created: mapDateTime(json, r'created', r'')!,
      updated: mapDateTime(json, r'updated', r'')!,
      entityId: mapValueOfType<String>(json, r'entity_id')!,
      name: mapValueOfType<String>(json, r'name')!,
      items: json[r'items'] is Iterable
          ? (json[r'items'] as Iterable).cast<int>().toList(growable: false)
          : const [],
      description: mapValueOfType<String>(json, r'description'),
      criteriaUrl: mapValueOfType<String>(json, r'criteria_url'),
      criteriaText: mapValueOfType<String>(json, r'criteria_text'),
      expiresAmount: mapValueOfType<int>(json, r'expires_amount'),
      expiresDuration: CredentialExpiresDuration.fromJson(json[r'expires_duration']),
      iconImage: mapValueOfType<String>(json, r'icon_image'),
      thumbnailImage: mapValueOfType<String>(json, r'thumbnail_image'),
      backgroundImage: mapValueOfType<String>(json, r'background_image'),
      credentialType: CredentialCredentialType.fromJson(json[r'credential_type']),
      tags: mapValueOfType<Object>(json, r'tags'),
      public: mapValueOfType<bool>(json, r'public'),
      metadata: mapValueOfType<Object>(json, r'metadata'),
      htmlTemplate: mapValueOfType<String>(json, r'html_template'),
      cssTemplate: mapValueOfType<String>(json, r'css_template'),
      issuingSignal: CredentialIssuingSignal.fromJson(json[r'issuing_signal']),
      issuer: mapValueOfType<int>(json, r'issuer'),
    );
  }
  return null;
}