fromJson static method

APITicket? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static APITicket? 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(() {
      assert(json.containsKey(r'_id'), 'Required key "APITicket[_id]" is missing from JSON.');
      assert(json[r'_id'] != null, 'Required key "APITicket[_id]" has a null value in JSON.');
      assert(json.containsKey(r'urlId'), 'Required key "APITicket[urlId]" is missing from JSON.');
      assert(json[r'urlId'] != null, 'Required key "APITicket[urlId]" has a null value in JSON.');
      assert(json.containsKey(r'userId'), 'Required key "APITicket[userId]" is missing from JSON.');
      assert(json[r'userId'] != null, 'Required key "APITicket[userId]" has a null value in JSON.');
      assert(json.containsKey(r'managedByTenantId'), 'Required key "APITicket[managedByTenantId]" is missing from JSON.');
      assert(json[r'managedByTenantId'] != null, 'Required key "APITicket[managedByTenantId]" has a null value in JSON.');
      assert(json.containsKey(r'assignedUserIds'), 'Required key "APITicket[assignedUserIds]" is missing from JSON.');
      assert(json[r'assignedUserIds'] != null, 'Required key "APITicket[assignedUserIds]" has a null value in JSON.');
      assert(json.containsKey(r'subject'), 'Required key "APITicket[subject]" is missing from JSON.');
      assert(json[r'subject'] != null, 'Required key "APITicket[subject]" has a null value in JSON.');
      assert(json.containsKey(r'createdAt'), 'Required key "APITicket[createdAt]" is missing from JSON.');
      assert(json[r'createdAt'] != null, 'Required key "APITicket[createdAt]" has a null value in JSON.');
      assert(json.containsKey(r'state'), 'Required key "APITicket[state]" is missing from JSON.');
      assert(json[r'state'] != null, 'Required key "APITicket[state]" has a null value in JSON.');
      assert(json.containsKey(r'fileCount'), 'Required key "APITicket[fileCount]" is missing from JSON.');
      assert(json[r'fileCount'] != null, 'Required key "APITicket[fileCount]" has a null value in JSON.');
      return true;
    }());

    return APITicket(
      id: mapValueOfType<String>(json, r'_id')!,
      urlId: mapValueOfType<String>(json, r'urlId')!,
      userId: mapValueOfType<String>(json, r'userId')!,
      managedByTenantId: mapValueOfType<String>(json, r'managedByTenantId')!,
      assignedUserIds: json[r'assignedUserIds'] is Iterable
          ? (json[r'assignedUserIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      subject: mapValueOfType<String>(json, r'subject')!,
      createdAt: mapValueOfType<String>(json, r'createdAt')!,
      state: mapValueOfType<int>(json, r'state')!,
      fileCount: mapValueOfType<int>(json, r'fileCount')!,
    );
  }
  return null;
}