fromJson static method

Wire? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static Wire? 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 "Wire[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "Wire[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return Wire(
      action: mapValueOfType<String>(json, r'action'),
      authMethod: mapValueOfType<String>(json, r'authMethod'),
      email: mapValueOfType<String>(json, r'email'),
      hash: mapValueOfType<String>(json, r'hash'),
      home: mapValueOfType<String>(json, r'home'),
      isAdmin: mapValueOfType<bool>(json, r'isAdmin'),
      method: mapValueOfType<String>(json, r'method'),
      org: mapValueOfType<String>(json, r'org'),
      path: mapValueOfType<String>(json, r'path'),
      prevHash: mapValueOfType<String>(json, r'prevHash'),
      reason: mapValueOfType<String>(json, r'reason'),
      requestId: mapValueOfType<String>(json, r'requestId'),
      resource: mapValueOfType<String>(json, r'resource'),
      resourceId: mapValueOfType<String>(json, r'resourceId'),
      result: mapValueOfType<String>(json, r'result'),
      seq: mapValueOfType<int>(json, r'seq'),
      sourceIp: mapValueOfType<String>(json, r'sourceIp'),
      status: mapValueOfType<int>(json, r'status'),
      sub: mapValueOfType<String>(json, r'sub'),
      time: mapValueOfType<String>(json, r'time'),
      userAgent: mapValueOfType<String>(json, r'userAgent'),
    );
  }
  return null;
}