AnalysisError.fromJson constructor

AnalysisError.fromJson(
  1. JsonDecoder jsonDecoder,
  2. String jsonPath,
  3. Object? json
)

Implementation

factory AnalysisError.fromJson(
    JsonDecoder jsonDecoder, String jsonPath, Object? json) {
  json ??= {};
  if (json is Map) {
    AnalysisErrorSeverity severity;
    if (json.containsKey('severity')) {
      severity = AnalysisErrorSeverity.fromJson(
          jsonDecoder, '$jsonPath.severity', json['severity']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'severity');
    }
    AnalysisErrorType type;
    if (json.containsKey('type')) {
      type = AnalysisErrorType.fromJson(
          jsonDecoder, '$jsonPath.type', json['type']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'type');
    }
    Location location;
    if (json.containsKey('location')) {
      location = Location.fromJson(
          jsonDecoder, '$jsonPath.location', json['location']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'location');
    }
    String message;
    if (json.containsKey('message')) {
      message =
          jsonDecoder.decodeString('$jsonPath.message', json['message']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'message');
    }
    String? correction;
    if (json.containsKey('correction')) {
      correction = jsonDecoder.decodeString(
          '$jsonPath.correction', json['correction']);
    }
    String code;
    if (json.containsKey('code')) {
      code = jsonDecoder.decodeString('$jsonPath.code', json['code']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'code');
    }
    String? url;
    if (json.containsKey('url')) {
      url = jsonDecoder.decodeString('$jsonPath.url', json['url']);
    }
    List<DiagnosticMessage>? contextMessages;
    if (json.containsKey('contextMessages')) {
      contextMessages = jsonDecoder.decodeList(
          '$jsonPath.contextMessages',
          json['contextMessages'],
          (String jsonPath, Object? json) =>
              DiagnosticMessage.fromJson(jsonDecoder, jsonPath, json));
    }
    bool? hasFix;
    if (json.containsKey('hasFix')) {
      hasFix = jsonDecoder.decodeBool('$jsonPath.hasFix', json['hasFix']);
    }
    return AnalysisError(severity, type, location, message, code,
        correction: correction,
        url: url,
        contextMessages: contextMessages,
        hasFix: hasFix);
  } else {
    throw jsonDecoder.mismatch(jsonPath, 'AnalysisError', json);
  }
}