fromJson static method

dynamic fromJson(
  1. dynamic value,
  2. String targetType, {
  3. bool growable = false,
})

Returns a native instance of an OpenAPI class matching the targetType.

Implementation

static dynamic fromJson(
  dynamic value,
  String targetType, {
  bool growable = false,
}) {
  try {
    switch (targetType) {
      case 'String':
        return value is String ? value : value.toString();
      case 'int':
        return value is int ? value : int.parse('$value');
      case 'double':
        return value is double ? value : double.parse('$value');
      case 'bool':
        if (value is bool) {
          return value;
        }
        final valueString = '$value'.toLowerCase();
        return valueString == 'true' || valueString == '1';
      case 'DateTime':
        return value is DateTime ? value : DateTime.tryParse(value);
      case 'APIError':
        return APIError.fromJson(value);
      case 'AcceptCallResponse':
        return AcceptCallResponse.fromJson(value);
      case 'Action':
        return Action.fromJson(value);
      case 'ActionLog':
        return ActionLog.fromJson(value);
      case 'AggregatedStats':
        return AggregatedStats.fromJson(value);
      case 'Attachment':
        return Attachment.fromJson(value);
      case 'AudioSettingsRequest':
        return AudioSettingsRequest.fromJson(value);
      case 'AudioSettingsResponse':
        return AudioSettingsResponse.fromJson(value);
      case 'BackstageSettingsRequest':
        return BackstageSettingsRequest.fromJson(value);
      case 'BackstageSettingsResponse':
        return BackstageSettingsResponse.fromJson(value);
      case 'Ban':
        return Ban.fromJson(value);
      case 'BlockListOptions':
        return BlockListOptions.fromJson(value);
      case 'BlockUserRequest':
        return BlockUserRequest.fromJson(value);
      case 'BlockUserResponse':
        return BlockUserResponse.fromJson(value);
      case 'BlockedUserEvent':
        return BlockedUserEvent.fromJson(value);
      case 'BroadcastSettingsRequest':
        return BroadcastSettingsRequest.fromJson(value);
      case 'BroadcastSettingsResponse':
        return BroadcastSettingsResponse.fromJson(value);
      case 'CallAcceptedEvent':
        return CallAcceptedEvent.fromJson(value);
      case 'CallClosedCaption':
        return CallClosedCaption.fromJson(value);
      case 'CallCreatedEvent':
        return CallCreatedEvent.fromJson(value);
      case 'CallDeletedEvent':
        return CallDeletedEvent.fromJson(value);
      case 'CallEndedEvent':
        return CallEndedEvent.fromJson(value);
      case 'CallEvent':
        return CallEvent.fromJson(value);
      case 'CallHLSBroadcastingFailedEvent':
        return CallHLSBroadcastingFailedEvent.fromJson(value);
      case 'CallHLSBroadcastingStartedEvent':
        return CallHLSBroadcastingStartedEvent.fromJson(value);
      case 'CallHLSBroadcastingStoppedEvent':
        return CallHLSBroadcastingStoppedEvent.fromJson(value);
      case 'CallIngressResponse':
        return CallIngressResponse.fromJson(value);
      case 'CallLiveStartedEvent':
        return CallLiveStartedEvent.fromJson(value);
      case 'CallMemberAddedEvent':
        return CallMemberAddedEvent.fromJson(value);
      case 'CallMemberRemovedEvent':
        return CallMemberRemovedEvent.fromJson(value);
      case 'CallMemberUpdatedEvent':
        return CallMemberUpdatedEvent.fromJson(value);
      case 'CallMemberUpdatedPermissionEvent':
        return CallMemberUpdatedPermissionEvent.fromJson(value);
      case 'CallMissedEvent':
        return CallMissedEvent.fromJson(value);
      case 'CallNotificationEvent':
        return CallNotificationEvent.fromJson(value);
      case 'CallParticipantResponse':
        return CallParticipantResponse.fromJson(value);
      case 'CallReactionEvent':
        return CallReactionEvent.fromJson(value);
      case 'CallRecording':
        return CallRecording.fromJson(value);
      case 'CallRecordingFailedEvent':
        return CallRecordingFailedEvent.fromJson(value);
      case 'CallRecordingReadyEvent':
        return CallRecordingReadyEvent.fromJson(value);
      case 'CallRecordingStartedEvent':
        return CallRecordingStartedEvent.fromJson(value);
      case 'CallRecordingStoppedEvent':
        return CallRecordingStoppedEvent.fromJson(value);
      case 'CallRejectedEvent':
        return CallRejectedEvent.fromJson(value);
      case 'CallRequest':
        return CallRequest.fromJson(value);
      case 'CallResponse':
        return CallResponse.fromJson(value);
      case 'CallRingEvent':
        return CallRingEvent.fromJson(value);
      case 'CallRtmpBroadcastFailedEvent':
        return CallRtmpBroadcastFailedEvent.fromJson(value);
      case 'CallRtmpBroadcastStartedEvent':
        return CallRtmpBroadcastStartedEvent.fromJson(value);
      case 'CallRtmpBroadcastStoppedEvent':
        return CallRtmpBroadcastStoppedEvent.fromJson(value);
      case 'CallSessionEndedEvent':
        return CallSessionEndedEvent.fromJson(value);
      case 'CallSessionParticipantCountsUpdatedEvent':
        return CallSessionParticipantCountsUpdatedEvent.fromJson(value);
      case 'CallSessionParticipantJoinedEvent':
        return CallSessionParticipantJoinedEvent.fromJson(value);
      case 'CallSessionParticipantLeftEvent':
        return CallSessionParticipantLeftEvent.fromJson(value);
      case 'CallSessionResponse':
        return CallSessionResponse.fromJson(value);
      case 'CallSessionStartedEvent':
        return CallSessionStartedEvent.fromJson(value);
      case 'CallSettingsRequest':
        return CallSettingsRequest.fromJson(value);
      case 'CallSettingsResponse':
        return CallSettingsResponse.fromJson(value);
      case 'CallStateResponseFields':
        return CallStateResponseFields.fromJson(value);
      case 'CallStatsReportSummaryResponse':
        return CallStatsReportSummaryResponse.fromJson(value);
      case 'CallTimeline':
        return CallTimeline.fromJson(value);
      case 'CallTranscription':
        return CallTranscription.fromJson(value);
      case 'CallTranscriptionFailedEvent':
        return CallTranscriptionFailedEvent.fromJson(value);
      case 'CallTranscriptionReadyEvent':
        return CallTranscriptionReadyEvent.fromJson(value);
      case 'CallTranscriptionStartedEvent':
        return CallTranscriptionStartedEvent.fromJson(value);
      case 'CallTranscriptionStoppedEvent':
        return CallTranscriptionStoppedEvent.fromJson(value);
      case 'CallUpdatedEvent':
        return CallUpdatedEvent.fromJson(value);
      case 'CallUserMutedEvent':
        return CallUserMutedEvent.fromJson(value);
      case 'Channel':
        return Channel.fromJson(value);
      case 'ChannelConfig':
        return ChannelConfig.fromJson(value);
      case 'ChannelConfigWithInfo':
        return ChannelConfigWithInfo.fromJson(value);
      case 'ChannelMember':
        return ChannelMember.fromJson(value);
      case 'ChannelMute':
        return ChannelMute.fromJson(value);
      case 'ChannelResponse':
        return ChannelResponse.fromJson(value);
      case 'ClosedCaptionEvent':
        return ClosedCaptionEvent.fromJson(value);
      case 'CollectUserFeedbackRequest':
        return CollectUserFeedbackRequest.fromJson(value);
      case 'CollectUserFeedbackResponse':
        return CollectUserFeedbackResponse.fromJson(value);
      case 'Command':
        return Command.fromJson(value);
      case 'ConnectUserDetailsRequest':
        return ConnectUserDetailsRequest.fromJson(value);
      case 'ConnectedEvent':
        return ConnectedEvent.fromJson(value);
      case 'ConnectionErrorEvent':
        return ConnectionErrorEvent.fromJson(value);
      case 'Coordinates':
        return Coordinates.fromJson(value);
      case 'Count':
        return Count.fromJson(value);
      case 'CountrywiseAggregateStats':
        return CountrywiseAggregateStats.fromJson(value);
      case 'CreateDeviceRequest':
        return CreateDeviceRequest.fromJson(value);
      case 'CreateGuestRequest':
        return CreateGuestRequest.fromJson(value);
      case 'CreateGuestResponse':
        return CreateGuestResponse.fromJson(value);
      case 'Credentials':
        return Credentials.fromJson(value);
      case 'CustomVideoEvent':
        return CustomVideoEvent.fromJson(value);
      case 'Data':
        return Data.fromJson(value);
      case 'DeleteCallRequest':
        return DeleteCallRequest.fromJson(value);
      case 'DeleteCallResponse':
        return DeleteCallResponse.fromJson(value);
      case 'DeleteRecordingResponse':
        return DeleteRecordingResponse.fromJson(value);
      case 'DeleteTranscriptionResponse':
        return DeleteTranscriptionResponse.fromJson(value);
      case 'Device':
        return Device.fromJson(value);
      case 'EdgeResponse':
        return EdgeResponse.fromJson(value);
      case 'EgressHLSResponse':
        return EgressHLSResponse.fromJson(value);
      case 'EgressRTMPResponse':
        return EgressRTMPResponse.fromJson(value);
      case 'EgressResponse':
        return EgressResponse.fromJson(value);
      case 'EndCallResponse':
        return EndCallResponse.fromJson(value);
      case 'EnrichedActivity':
        return EnrichedActivity.fromJson(value);
      case 'EnrichedReaction':
        return EnrichedReaction.fromJson(value);
      case 'Field':
        return Field.fromJson(value);
      case 'Flag2':
        return Flag2.fromJson(value);
      case 'GeofenceSettingsRequest':
        return GeofenceSettingsRequest.fromJson(value);
      case 'GeofenceSettingsResponse':
        return GeofenceSettingsResponse.fromJson(value);
      case 'GeolocationResult':
        return GeolocationResult.fromJson(value);
      case 'GetCallResponse':
        return GetCallResponse.fromJson(value);
      case 'GetCallStatsResponse':
        return GetCallStatsResponse.fromJson(value);
      case 'GetEdgesResponse':
        return GetEdgesResponse.fromJson(value);
      case 'GetOrCreateCallRequest':
        return GetOrCreateCallRequest.fromJson(value);
      case 'GetOrCreateCallResponse':
        return GetOrCreateCallResponse.fromJson(value);
      case 'GoLiveRequest':
        return GoLiveRequest.fromJson(value);
      case 'GoLiveResponse':
        return GoLiveResponse.fromJson(value);
      case 'HLSSettingsRequest':
        return HLSSettingsRequest.fromJson(value);
      case 'HLSSettingsResponse':
        return HLSSettingsResponse.fromJson(value);
      case 'HealthCheckEvent':
        return HealthCheckEvent.fromJson(value);
      case 'ICEServer':
        return ICEServer.fromJson(value);
      case 'ImageData':
        return ImageData.fromJson(value);
      case 'Images':
        return Images.fromJson(value);
      case 'JoinCallRequest':
        return JoinCallRequest.fromJson(value);
      case 'JoinCallResponse':
        return JoinCallResponse.fromJson(value);
      case 'LabelThresholds':
        return LabelThresholds.fromJson(value);
      case 'LayoutSettingsRequest':
        return LayoutSettingsRequest.fromJson(value);
      case 'LimitsSettingsRequest':
        return LimitsSettingsRequest.fromJson(value);
      case 'LimitsSettingsResponse':
        return LimitsSettingsResponse.fromJson(value);
      case 'ListDevicesResponse':
        return ListDevicesResponse.fromJson(value);
      case 'ListRecordingsResponse':
        return ListRecordingsResponse.fromJson(value);
      case 'ListTranscriptionsResponse':
        return ListTranscriptionsResponse.fromJson(value);
      case 'Location':
        return Location.fromJson(value);
      case 'MOSStats':
        return MOSStats.fromJson(value);
      case 'MediaPubSubHint':
        return MediaPubSubHint.fromJson(value);
      case 'MemberRequest':
        return MemberRequest.fromJson(value);
      case 'MemberResponse':
        return MemberResponse.fromJson(value);
      case 'Message':
        return Message.fromJson(value);
      case 'ModerationCustomActionEvent':
        return ModerationCustomActionEvent.fromJson(value);
      case 'ModerationFlaggedEvent':
        return ModerationFlaggedEvent.fromJson(value);
      case 'ModerationMarkReviewedEvent':
        return ModerationMarkReviewedEvent.fromJson(value);
      case 'ModerationPayload':
        return ModerationPayload.fromJson(value);
      case 'MuteUsersRequest':
        return MuteUsersRequest.fromJson(value);
      case 'MuteUsersResponse':
        return MuteUsersResponse.fromJson(value);
      case 'NoiseCancellationSettings':
        return NoiseCancellationSettings.fromJson(value);
      case 'NullBool':
        return NullBool.fromJson(value);
      case 'NullTime':
        return NullTime.fromJson(value);
      case 'OwnCapability':
        return OwnCapabilityTypeTransformer().decode(value);
      case 'OwnUserResponse':
        return OwnUserResponse.fromJson(value);
      case 'PermissionRequestEvent':
        return PermissionRequestEvent.fromJson(value);
      case 'PinRequest':
        return PinRequest.fromJson(value);
      case 'PinResponse':
        return PinResponse.fromJson(value);
      case 'Poll':
        return Poll.fromJson(value);
      case 'PollOption':
        return PollOption.fromJson(value);
      case 'PollVote':
        return PollVote.fromJson(value);
      case 'PrivacySettings':
        return PrivacySettings.fromJson(value);
      case 'PrivacySettingsResponse':
        return PrivacySettingsResponse.fromJson(value);
      case 'PublishedTrackInfo':
        return PublishedTrackInfo.fromJson(value);
      case 'PublisherAggregateStats':
        return PublisherAggregateStats.fromJson(value);
      case 'PushNotificationSettings':
        return PushNotificationSettings.fromJson(value);
      case 'PushNotificationSettingsInput':
        return PushNotificationSettingsInput.fromJson(value);
      case 'PushNotificationSettingsResponse':
        return PushNotificationSettingsResponse.fromJson(value);
      case 'QueryCallMembersRequest':
        return QueryCallMembersRequest.fromJson(value);
      case 'QueryCallMembersResponse':
        return QueryCallMembersResponse.fromJson(value);
      case 'QueryCallStatsRequest':
        return QueryCallStatsRequest.fromJson(value);
      case 'QueryCallStatsResponse':
        return QueryCallStatsResponse.fromJson(value);
      case 'QueryCallsRequest':
        return QueryCallsRequest.fromJson(value);
      case 'QueryCallsResponse':
        return QueryCallsResponse.fromJson(value);
      case 'RTMPBroadcastRequest':
        return RTMPBroadcastRequest.fromJson(value);
      case 'RTMPIngress':
        return RTMPIngress.fromJson(value);
      case 'RTMPSettingsRequest':
        return RTMPSettingsRequest.fromJson(value);
      case 'RTMPSettingsResponse':
        return RTMPSettingsResponse.fromJson(value);
      case 'Reaction':
        return Reaction.fromJson(value);
      case 'ReactionGroupResponse':
        return ReactionGroupResponse.fromJson(value);
      case 'ReactionResponse':
        return ReactionResponse.fromJson(value);
      case 'ReadReceipts':
        return ReadReceipts.fromJson(value);
      case 'ReadReceiptsResponse':
        return ReadReceiptsResponse.fromJson(value);
      case 'RecordSettingsRequest':
        return RecordSettingsRequest.fromJson(value);
      case 'RecordSettingsResponse':
        return RecordSettingsResponse.fromJson(value);
      case 'RejectCallRequest':
        return RejectCallRequest.fromJson(value);
      case 'RejectCallResponse':
        return RejectCallResponse.fromJson(value);
      case 'RequestPermissionRequest':
        return RequestPermissionRequest.fromJson(value);
      case 'RequestPermissionResponse':
        return RequestPermissionResponse.fromJson(value);
      // MANUAL_EDIT: Response -> DurationResponse
      case 'DurationResponse':
        return DurationResponse.fromJson(value);
      case 'ReviewQueueItem':
        return ReviewQueueItem.fromJson(value);
      case 'RingSettingsRequest':
        return RingSettingsRequest.fromJson(value);
      case 'RingSettingsResponse':
        return RingSettingsResponse.fromJson(value);
      case 'SFULocationResponse':
        return SFULocationResponse.fromJson(value);
      case 'SFUResponse':
        return SFUResponse.fromJson(value);
      case 'ScreensharingSettingsRequest':
        return ScreensharingSettingsRequest.fromJson(value);
      case 'ScreensharingSettingsResponse':
        return ScreensharingSettingsResponse.fromJson(value);
      case 'SendCallEventRequest':
        return SendCallEventRequest.fromJson(value);
      case 'SendCallEventResponse':
        return SendCallEventResponse.fromJson(value);
      case 'SendReactionRequest':
        return SendReactionRequest.fromJson(value);
      case 'SendReactionResponse':
        return SendReactionResponse.fromJson(value);
      case 'SortParamRequest':
        return SortParamRequest.fromJson(value);
      case 'StartHLSBroadcastingResponse':
        return StartHLSBroadcastingResponse.fromJson(value);
      case 'StartRTMPBroadcastsRequest':
        return StartRTMPBroadcastsRequest.fromJson(value);
      case 'StartRTMPBroadcastsResponse':
        return StartRTMPBroadcastsResponse.fromJson(value);
      case 'StartRecordingRequest':
        return StartRecordingRequest.fromJson(value);
      case 'StartRecordingResponse':
        return StartRecordingResponse.fromJson(value);
      case 'StartTranscriptionRequest':
        return StartTranscriptionRequest.fromJson(value);
      case 'StartTranscriptionResponse':
        return StartTranscriptionResponse.fromJson(value);
      case 'StatsOptions':
        return StatsOptions.fromJson(value);
      case 'StopAllRTMPBroadcastsResponse':
        return StopAllRTMPBroadcastsResponse.fromJson(value);
      case 'StopHLSBroadcastingResponse':
        return StopHLSBroadcastingResponse.fromJson(value);
      case 'StopLiveResponse':
        return StopLiveResponse.fromJson(value);
      case 'StopRTMPBroadcastsResponse':
        return StopRTMPBroadcastsResponse.fromJson(value);
      case 'StopRecordingResponse':
        return StopRecordingResponse.fromJson(value);
      case 'StopTranscriptionResponse':
        return StopTranscriptionResponse.fromJson(value);
      case 'Subsession':
        return Subsession.fromJson(value);
      case 'TURNAggregatedStats':
        return TURNAggregatedStats.fromJson(value);
      case 'TargetResolution':
        return TargetResolution.fromJson(value);
      case 'Thresholds':
        return Thresholds.fromJson(value);
      case 'ThumbnailResponse':
        return ThumbnailResponse.fromJson(value);
      case 'ThumbnailsSettingsRequest':
        return ThumbnailsSettingsRequest.fromJson(value);
      case 'ThumbnailsSettingsResponse':
        return ThumbnailsSettingsResponse.fromJson(value);
      case 'TimeStats':
        return TimeStats.fromJson(value);
      case 'TranscriptionSettingsRequest':
        return TranscriptionSettingsRequest.fromJson(value);
      case 'TranscriptionSettingsResponse':
        return TranscriptionSettingsResponse.fromJson(value);
      case 'TypingIndicators':
        return TypingIndicators.fromJson(value);
      case 'TypingIndicatorsResponse':
        return TypingIndicatorsResponse.fromJson(value);
      case 'UnblockUserRequest':
        return UnblockUserRequest.fromJson(value);
      case 'UnblockUserResponse':
        return UnblockUserResponse.fromJson(value);
      case 'UnblockedUserEvent':
        return UnblockedUserEvent.fromJson(value);
      case 'UnpinRequest':
        return UnpinRequest.fromJson(value);
      case 'UnpinResponse':
        return UnpinResponse.fromJson(value);
      case 'UpdateCallMembersRequest':
        return UpdateCallMembersRequest.fromJson(value);
      case 'UpdateCallMembersResponse':
        return UpdateCallMembersResponse.fromJson(value);
      case 'UpdateCallRequest':
        return UpdateCallRequest.fromJson(value);
      case 'UpdateCallResponse':
        return UpdateCallResponse.fromJson(value);
      case 'UpdateUserPermissionsRequest':
        return UpdateUserPermissionsRequest.fromJson(value);
      case 'UpdateUserPermissionsResponse':
        return UpdateUserPermissionsResponse.fromJson(value);
      case 'UpdatedCallPermissionsEvent':
        return UpdatedCallPermissionsEvent.fromJson(value);
      case 'UserBannedEvent':
        return UserBannedEvent.fromJson(value);
      case 'UserDeactivatedEvent':
        return UserDeactivatedEvent.fromJson(value);
      case 'UserDeletedEvent':
        return UserDeletedEvent.fromJson(value);
      case 'UserEventPayload':
        return UserEventPayload.fromJson(value);
      case 'UserFlaggedEvent':
        return UserFlaggedEvent.fromJson(value);
      case 'UserInfoResponse':
        return UserInfoResponse.fromJson(value);
      case 'UserMuteResponse':
        return UserMuteResponse.fromJson(value);
      case 'UserMutedEvent':
        return UserMutedEvent.fromJson(value);
      case 'UserObject':
        return UserObject.fromJson(value);
      case 'UserPresenceChangedEvent':
        return UserPresenceChangedEvent.fromJson(value);
      case 'UserReactivatedEvent':
        return UserReactivatedEvent.fromJson(value);
      case 'UserRequest':
        return UserRequest.fromJson(value);
      case 'UserResponse':
        return UserResponse.fromJson(value);
      case 'UserSessionStats':
        return UserSessionStats.fromJson(value);
      case 'UserStats':
        return UserStats.fromJson(value);
      case 'UserUnbannedEvent':
        return UserUnbannedEvent.fromJson(value);
      case 'UserUnmutedEvent':
        return UserUnmutedEvent.fromJson(value);
      case 'UserUpdatedEvent':
        return UserUpdatedEvent.fromJson(value);
      case 'VideoQuality':
        return VideoQuality.fromJson(value);
      case 'VideoResolution':
        return VideoResolution.fromJson(value);
      case 'VideoSettingsRequest':
        return VideoSettingsRequest.fromJson(value);
      case 'VideoSettingsResponse':
        return VideoSettingsResponse.fromJson(value);
      case 'WSAuthMessage':
        return WSAuthMessage.fromJson(value);
      case 'WSClientEvent':
        return WSClientEvent.fromJson(value);
      case 'WSEvent':
        return WSEvent.fromJson(value);
      case 'WebhookEvent':
        return WebhookEvent.fromJson(value);
      default:
        dynamic match;
        if (value is List &&
            (match = _regList.firstMatch(targetType)?.group(1)) != null) {
          return value
              .map<dynamic>((dynamic v) => fromJson(
                    v,
                    match,
                    growable: growable,
                  ))
              .toList(growable: growable);
        }
        if (value is Set &&
            (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
          return value
              .map<dynamic>((dynamic v) => fromJson(
                    v,
                    match,
                    growable: growable,
                  ))
              .toSet();
        }
        if (value is Map &&
            (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
          return Map<String, dynamic>.fromIterables(
            value.keys.cast<String>(),
            value.values.map<dynamic>((dynamic v) => fromJson(
                  v,
                  match,
                  growable: growable,
                )),
          );
        }
    }
  } on Exception catch (error, trace) {
    throw ApiException.withInner(
      HttpStatus.internalServerError,
      'Exception during deserialization.',
      error,
      trace,
    );
  }
  throw ApiException(
    HttpStatus.internalServerError,
    'Could not find a suitable class for deserialization',
  );
}