Contents.fromJson constructor

Contents.fromJson(
  1. Object? json
)

Creates contents from JSON-compatible values.

Implementation

factory Contents.fromJson(Object? json) {
  if (json == null) {
    return Contents.empty;
  }
  if (json is String) {
    return Contents.text(json);
  }
  if (json is Map<String, Object?>) {
    return Contents([Content.fromJson(json)]);
  }
  if (json is List<Object?>) {
    return Contents(
      json
          .whereType<Map<String, Object?>>()
          .map(Content.fromJson)
          .toList(growable: false),
    );
  }
  throw FormatException('Unsupported message content JSON: $json');
}