MountedVolumeConsumer.fromJson constructor

MountedVolumeConsumer.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory MountedVolumeConsumer.fromJson(Map<String, dynamic> json) {
  final kind = switch (json['kind']) {
    'room' => MountedVolumeConsumerKind.room,
    'container' => MountedVolumeConsumerKind.container,
    _ => throw RoomServerException('unexpected return type from mounts.list'),
  };
  final containerId = json['container_id'] as String?;
  if (kind == MountedVolumeConsumerKind.container && containerId == null) {
    throw RoomServerException('unexpected return type from mounts.list');
  }
  if (kind == MountedVolumeConsumerKind.room && containerId != null) {
    throw RoomServerException('unexpected return type from mounts.list');
  }
  return MountedVolumeConsumer(kind: kind, containerId: containerId);
}