CompletionGetSuggestionsResult.fromJson constructor

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

Implementation

factory CompletionGetSuggestionsResult.fromJson(
    JsonDecoder jsonDecoder, String jsonPath, Object? json) {
  json ??= {};
  if (json is Map) {
    int replacementOffset;
    if (json.containsKey('replacementOffset')) {
      replacementOffset = jsonDecoder.decodeInt(
          '$jsonPath.replacementOffset', json['replacementOffset']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'replacementOffset');
    }
    int replacementLength;
    if (json.containsKey('replacementLength')) {
      replacementLength = jsonDecoder.decodeInt(
          '$jsonPath.replacementLength', json['replacementLength']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'replacementLength');
    }
    List<CompletionSuggestion> results;
    if (json.containsKey('results')) {
      results = jsonDecoder.decodeList(
          '$jsonPath.results',
          json['results'],
          (String jsonPath, Object? json) =>
              CompletionSuggestion.fromJson(jsonDecoder, jsonPath, json));
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'results');
    }
    return CompletionGetSuggestionsResult(
        replacementOffset, replacementLength, results);
  } else {
    throw jsonDecoder.mismatch(
        jsonPath, 'completion.getSuggestions result', json);
  }
}