fromJson static method

SIPTrunkResponse? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static SIPTrunkResponse? 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'allowed_ips'),
          'Required key "SIPTrunkResponse[allowed_ips]" is missing from JSON.');
      assert(json[r'allowed_ips'] != null,
          'Required key "SIPTrunkResponse[allowed_ips]" has a null value in JSON.');
      assert(json.containsKey(r'created_at'),
          'Required key "SIPTrunkResponse[created_at]" is missing from JSON.');
      assert(json[r'created_at'] != null,
          'Required key "SIPTrunkResponse[created_at]" has a null value in JSON.');
      assert(json.containsKey(r'id'),
          'Required key "SIPTrunkResponse[id]" is missing from JSON.');
      assert(json[r'id'] != null,
          'Required key "SIPTrunkResponse[id]" has a null value in JSON.');
      assert(json.containsKey(r'name'),
          'Required key "SIPTrunkResponse[name]" is missing from JSON.');
      assert(json[r'name'] != null,
          'Required key "SIPTrunkResponse[name]" has a null value in JSON.');
      assert(json.containsKey(r'numbers'),
          'Required key "SIPTrunkResponse[numbers]" is missing from JSON.');
      assert(json[r'numbers'] != null,
          'Required key "SIPTrunkResponse[numbers]" has a null value in JSON.');
      assert(json.containsKey(r'password'),
          'Required key "SIPTrunkResponse[password]" is missing from JSON.');
      assert(json[r'password'] != null,
          'Required key "SIPTrunkResponse[password]" has a null value in JSON.');
      assert(json.containsKey(r'updated_at'),
          'Required key "SIPTrunkResponse[updated_at]" is missing from JSON.');
      assert(json[r'updated_at'] != null,
          'Required key "SIPTrunkResponse[updated_at]" has a null value in JSON.');
      assert(json.containsKey(r'uri'),
          'Required key "SIPTrunkResponse[uri]" is missing from JSON.');
      assert(json[r'uri'] != null,
          'Required key "SIPTrunkResponse[uri]" has a null value in JSON.');
      assert(json.containsKey(r'username'),
          'Required key "SIPTrunkResponse[username]" is missing from JSON.');
      assert(json[r'username'] != null,
          'Required key "SIPTrunkResponse[username]" has a null value in JSON.');
      return true;
    }());

    return SIPTrunkResponse(
      allowedIps: json[r'allowed_ips'] is Iterable
          ? (json[r'allowed_ips'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      createdAt: mapDateTime(json, r'created_at', r'')!,
      id: mapValueOfType<String>(json, r'id')!,
      name: mapValueOfType<String>(json, r'name')!,
      numbers: json[r'numbers'] is Iterable
          ? (json[r'numbers'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      password: mapValueOfType<String>(json, r'password')!,
      updatedAt: mapDateTime(json, r'updated_at', r'')!,
      uri: mapValueOfType<String>(json, r'uri')!,
      username: mapValueOfType<String>(json, r'username')!,
    );
  }
  return null;
}