fromJson static method

O11yHTTPClientConfig? fromJson(
  1. dynamic value
)

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

Implementation

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

    return O11yHTTPClientConfig(
      authorization: O11yAuthorization.fromJson(json[r'authorization']),
      basicAuth: O11yBasicAuth.fromJson(json[r'basic_auth']),
      bearerToken: mapValueOfType<Object>(json, r'bearer_token'),
      bearerTokenFile: mapValueOfType<String>(json, r'bearer_token_file'),
      enableHttp2: mapValueOfType<bool>(json, r'enable_http2'),
      followRedirects: mapValueOfType<bool>(json, r'follow_redirects'),
      httpHeaders: mapValueOfType<Object>(json, r'http_headers'),
      noProxy: mapValueOfType<String>(json, r'no_proxy'),
      oauth2: O11yOAuth2.fromJson(json[r'oauth2']),
      proxyConnectHeader: json[r'proxy_connect_header'] == null
        ? const {}
          : (json[r'proxy_connect_header'] as Map).map((k, v) => MapEntry(k as String, v == null ? const <Object>[] : (v as List).cast<Object>().toList(growable: false))),
      proxyFromEnvironment: mapValueOfType<bool>(json, r'proxy_from_environment'),
      proxyUrl: mapValueOfType<Object>(json, r'proxy_url'),
      tlsConfig: O11yTLSConfig.fromJson(json[r'tls_config']),
    );
  }
  return null;
}