CompletionGetSuggestionsResult.fromJson constructor

CompletionGetSuggestionsResult.fromJson(
  1. JsonDecoder jsonDecoder,
  2. String jsonPath,
  3. Object? json, {
  4. ClientUriConverter? clientUriConverter,
})

Implementation

factory CompletionGetSuggestionsResult.fromJson(
  JsonDecoder jsonDecoder,
  String jsonPath,
  Object? json, {
  ClientUriConverter? clientUriConverter,
}) {
  json ??= {};
  if (json is! Map) {
    throw jsonDecoder.mismatch(
      jsonPath,
      "'completion.getSuggestions result'",
      json,
    );
  }
  int replacementOffset;
  if (json case {'replacementOffset': var encodedReplacementOffset}) {
    replacementOffset = jsonDecoder.decodeInt(
      '$jsonPath.replacementOffset',
      encodedReplacementOffset,
    );
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'replacementOffset'", json);
  }
  int replacementLength;
  if (json case {'replacementLength': var encodedReplacementLength}) {
    replacementLength = jsonDecoder.decodeInt(
      '$jsonPath.replacementLength',
      encodedReplacementLength,
    );
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'replacementLength'", json);
  }
  List<CompletionSuggestion> results;
  if (json case {'results': var encodedResults}) {
    results = jsonDecoder.decodeList(
      '$jsonPath.results',
      encodedResults,
      (String jsonPath, Object? json) => CompletionSuggestion.fromJson(
        jsonDecoder,
        jsonPath,
        json,
        clientUriConverter: clientUriConverter,
      ),
    );
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'results'", json);
  }
  return CompletionGetSuggestionsResult(
    replacementOffset,
    replacementLength,
    results,
  );
}