Candidate.fromJson constructor

Candidate.fromJson(
  1. Object? j
)

Implementation

factory Candidate.fromJson(Object? j) {
  final json = j as Map<String, Object?>;
  return Candidate(
    index: switch (json['index']) {
      null => null,
      Object $1 => decodeInt($1),
    },
    content: switch (json['content']) {
      null => null,
      Object $1 => Content.fromJson($1),
    },
    finishReason: switch (json['finishReason']) {
      null => Candidate_FinishReason.$default,
      Object $1 => Candidate_FinishReason.fromJson($1),
    },
    finishMessage: switch (json['finishMessage']) {
      null => null,
      Object $1 => decodeString($1),
    },
    safetyRatings: switch (json['safetyRatings']) {
      null => [],
      List<Object?> $1 => [for (final i in $1) SafetyRating.fromJson(i)],
      _ => throw const FormatException('"safetyRatings" is not a list'),
    },
    citationMetadata: switch (json['citationMetadata']) {
      null => null,
      Object $1 => CitationMetadata.fromJson($1),
    },
    tokenCount: switch (json['tokenCount']) {
      null => 0,
      Object $1 => decodeInt($1),
    },
    groundingAttributions: switch (json['groundingAttributions']) {
      null => [],
      List<Object?> $1 => [
        for (final i in $1) GroundingAttribution.fromJson(i),
      ],
      _ => throw const FormatException(
        '"groundingAttributions" is not a list',
      ),
    },
    groundingMetadata: switch (json['groundingMetadata']) {
      null => null,
      Object $1 => GroundingMetadata.fromJson($1),
    },
    avgLogprobs: switch (json['avgLogprobs']) {
      null => 0,
      Object $1 => decodeDouble($1),
    },
    logprobsResult: switch (json['logprobsResult']) {
      null => null,
      Object $1 => LogprobsResult.fromJson($1),
    },
    urlContextMetadata: switch (json['urlContextMetadata']) {
      null => null,
      Object $1 => UrlContextMetadata.fromJson($1),
    },
  );
}