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) {
    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,
          clientUriConverter: clientUriConverter,
        ),
      );
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'results');
    }
    return CompletionGetSuggestionsResult(
      replacementOffset,
      replacementLength,
      results,
    );
  } else {
    throw jsonDecoder.mismatch(
      jsonPath,
      'completion.getSuggestions result',
      json,
    );
  }
}