deserialize<T> method

  1. @override
T deserialize<T>(
  1. dynamic data, [
  2. Type? t
])
override

Deserialize the provided json data to an object of type t or T.

Implementation

@override
T deserialize<T>(
  dynamic data, [
  Type? t,
]) {
  t ??= T;

  final dataClassName = getClassNameFromObjectJson(data);
  if (dataClassName != null && dataClassName != getClassNameForType(t)) {
    try {
      return deserializeByClassName({
        'className': dataClassName,
        'data': data,
      });
    } on FormatException catch (_) {
      // If the className is not recognized (e.g., older client receiving
      // data with a new subtype), fall back to deserializing without the
      // className, using the expected type T.
    }
  }

  if (t == _i4.RevokedAuthenticationAuthId) {
    return _i4.RevokedAuthenticationAuthId.fromJson(data) as T;
  }
  if (t == _i5.RevokedAuthenticationScope) {
    return _i5.RevokedAuthenticationScope.fromJson(data) as T;
  }
  if (t == _i6.RevokedAuthenticationUser) {
    return _i6.RevokedAuthenticationUser.fromJson(data) as T;
  }
  if (t == _i7.CacheInfo) {
    return _i7.CacheInfo.fromJson(data) as T;
  }
  if (t == _i8.CachesInfo) {
    return _i8.CachesInfo.fromJson(data) as T;
  }
  if (t == _i9.CloudStorageEntry) {
    return _i9.CloudStorageEntry.fromJson(data) as T;
  }
  if (t == _i10.CloudStorageDirectUploadEntry) {
    return _i10.CloudStorageDirectUploadEntry.fromJson(data) as T;
  }
  if (t == _i11.ClusterInfo) {
    return _i11.ClusterInfo.fromJson(data) as T;
  }
  if (t == _i12.ClusterServerInfo) {
    return _i12.ClusterServerInfo.fromJson(data) as T;
  }
  if (t == _i13.CronFutureCallScheduling) {
    return _i13.CronFutureCallScheduling.fromJson(data) as T;
  }
  if (t == _i14.DatabaseMigrationVersion) {
    return _i14.DatabaseMigrationVersion.fromJson(data) as T;
  }
  if (t == _i15.DistributedCacheEntry) {
    return _i15.DistributedCacheEntry.fromJson(data) as T;
  }
  if (t == _i16.AccessDeniedException) {
    return _i16.AccessDeniedException.fromJson(data) as T;
  }
  if (t == _i17.FileNotFoundException) {
    return _i17.FileNotFoundException.fromJson(data) as T;
  }
  if (t == _i18.FutureCallClaimEntry) {
    return _i18.FutureCallClaimEntry.fromJson(data) as T;
  }
  if (t == _i19.FutureCallEntry) {
    return _i19.FutureCallEntry.fromJson(data) as T;
  }
  if (t == _i13.IntervalFutureCallScheduling) {
    return _i13.IntervalFutureCallScheduling.fromJson(data) as T;
  }
  if (t == _i20.LogEntry) {
    return _i20.LogEntry.fromJson(data) as T;
  }
  if (t == _i21.LogLevel) {
    return _i21.LogLevel.fromJson(data) as T;
  }
  if (t == _i22.LogResult) {
    return _i22.LogResult.fromJson(data) as T;
  }
  if (t == _i23.LogSettings) {
    return _i23.LogSettings.fromJson(data) as T;
  }
  if (t == _i24.LogSettingsOverride) {
    return _i24.LogSettingsOverride.fromJson(data) as T;
  }
  if (t == _i25.MessageLogEntry) {
    return _i25.MessageLogEntry.fromJson(data) as T;
  }
  if (t == _i26.MethodInfo) {
    return _i26.MethodInfo.fromJson(data) as T;
  }
  if (t == _i27.QueryLogEntry) {
    return _i27.QueryLogEntry.fromJson(data) as T;
  }
  if (t == _i28.ReadWriteTestEntry) {
    return _i28.ReadWriteTestEntry.fromJson(data) as T;
  }
  if (t == _i29.RuntimeSettings) {
    return _i29.RuntimeSettings.fromJson(data) as T;
  }
  if (t == _i30.ServerHealthConnectionInfo) {
    return _i30.ServerHealthConnectionInfo.fromJson(data) as T;
  }
  if (t == _i31.ServerHealthMetric) {
    return _i31.ServerHealthMetric.fromJson(data) as T;
  }
  if (t == _i32.ServerHealthResult) {
    return _i32.ServerHealthResult.fromJson(data) as T;
  }
  if (t == _i33.ServerpodSqlException) {
    return _i33.ServerpodSqlException.fromJson(data) as T;
  }
  if (t == _i34.SessionLogEntry) {
    return _i34.SessionLogEntry.fromJson(data) as T;
  }
  if (t == _i35.SessionLogFilter) {
    return _i35.SessionLogFilter.fromJson(data) as T;
  }
  if (t == _i36.SessionLogInfo) {
    return _i36.SessionLogInfo.fromJson(data) as T;
  }
  if (t == _i37.SessionLogResult) {
    return _i37.SessionLogResult.fromJson(data) as T;
  }
  if (t == _i1.getType<_i4.RevokedAuthenticationAuthId?>()) {
    return (data != null
            ? _i4.RevokedAuthenticationAuthId.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i5.RevokedAuthenticationScope?>()) {
    return (data != null
            ? _i5.RevokedAuthenticationScope.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i6.RevokedAuthenticationUser?>()) {
    return (data != null
            ? _i6.RevokedAuthenticationUser.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i7.CacheInfo?>()) {
    return (data != null ? _i7.CacheInfo.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i8.CachesInfo?>()) {
    return (data != null ? _i8.CachesInfo.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i9.CloudStorageEntry?>()) {
    return (data != null ? _i9.CloudStorageEntry.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i10.CloudStorageDirectUploadEntry?>()) {
    return (data != null
            ? _i10.CloudStorageDirectUploadEntry.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i11.ClusterInfo?>()) {
    return (data != null ? _i11.ClusterInfo.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i12.ClusterServerInfo?>()) {
    return (data != null ? _i12.ClusterServerInfo.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i13.CronFutureCallScheduling?>()) {
    return (data != null
            ? _i13.CronFutureCallScheduling.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i14.DatabaseMigrationVersion?>()) {
    return (data != null
            ? _i14.DatabaseMigrationVersion.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i15.DistributedCacheEntry?>()) {
    return (data != null ? _i15.DistributedCacheEntry.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i16.AccessDeniedException?>()) {
    return (data != null ? _i16.AccessDeniedException.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i17.FileNotFoundException?>()) {
    return (data != null ? _i17.FileNotFoundException.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i18.FutureCallClaimEntry?>()) {
    return (data != null ? _i18.FutureCallClaimEntry.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i19.FutureCallEntry?>()) {
    return (data != null ? _i19.FutureCallEntry.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i13.IntervalFutureCallScheduling?>()) {
    return (data != null
            ? _i13.IntervalFutureCallScheduling.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i20.LogEntry?>()) {
    return (data != null ? _i20.LogEntry.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i21.LogLevel?>()) {
    return (data != null ? _i21.LogLevel.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i22.LogResult?>()) {
    return (data != null ? _i22.LogResult.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i23.LogSettings?>()) {
    return (data != null ? _i23.LogSettings.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i24.LogSettingsOverride?>()) {
    return (data != null ? _i24.LogSettingsOverride.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i25.MessageLogEntry?>()) {
    return (data != null ? _i25.MessageLogEntry.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i26.MethodInfo?>()) {
    return (data != null ? _i26.MethodInfo.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i27.QueryLogEntry?>()) {
    return (data != null ? _i27.QueryLogEntry.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i28.ReadWriteTestEntry?>()) {
    return (data != null ? _i28.ReadWriteTestEntry.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i29.RuntimeSettings?>()) {
    return (data != null ? _i29.RuntimeSettings.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i30.ServerHealthConnectionInfo?>()) {
    return (data != null
            ? _i30.ServerHealthConnectionInfo.fromJson(data)
            : null)
        as T;
  }
  if (t == _i1.getType<_i31.ServerHealthMetric?>()) {
    return (data != null ? _i31.ServerHealthMetric.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i32.ServerHealthResult?>()) {
    return (data != null ? _i32.ServerHealthResult.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i33.ServerpodSqlException?>()) {
    return (data != null ? _i33.ServerpodSqlException.fromJson(data) : null)
        as T;
  }
  if (t == _i1.getType<_i34.SessionLogEntry?>()) {
    return (data != null ? _i34.SessionLogEntry.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i35.SessionLogFilter?>()) {
    return (data != null ? _i35.SessionLogFilter.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i36.SessionLogInfo?>()) {
    return (data != null ? _i36.SessionLogInfo.fromJson(data) : null) as T;
  }
  if (t == _i1.getType<_i37.SessionLogResult?>()) {
    return (data != null ? _i37.SessionLogResult.fromJson(data) : null) as T;
  }
  if (t == List<String>) {
    return (data as List).map((e) => deserialize<String>(e)).toList() as T;
  }
  if (t == _i1.getType<List<String>?>()) {
    return (data != null
            ? (data as List).map((e) => deserialize<String>(e)).toList()
            : null)
        as T;
  }
  if (t == List<_i12.ClusterServerInfo>) {
    return (data as List)
            .map((e) => deserialize<_i12.ClusterServerInfo>(e))
            .toList()
        as T;
  }
  if (t == List<_i20.LogEntry>) {
    return (data as List).map((e) => deserialize<_i20.LogEntry>(e)).toList()
        as T;
  }
  if (t == List<_i24.LogSettingsOverride>) {
    return (data as List)
            .map((e) => deserialize<_i24.LogSettingsOverride>(e))
            .toList()
        as T;
  }
  if (t == List<_i31.ServerHealthMetric>) {
    return (data as List)
            .map((e) => deserialize<_i31.ServerHealthMetric>(e))
            .toList()
        as T;
  }
  if (t == List<_i30.ServerHealthConnectionInfo>) {
    return (data as List)
            .map((e) => deserialize<_i30.ServerHealthConnectionInfo>(e))
            .toList()
        as T;
  }
  if (t == _i1.getType<List<_i20.LogEntry>?>()) {
    return (data != null
            ? (data as List)
                  .map((e) => deserialize<_i20.LogEntry>(e))
                  .toList()
            : null)
        as T;
  }
  if (t == List<_i27.QueryLogEntry>) {
    return (data as List)
            .map((e) => deserialize<_i27.QueryLogEntry>(e))
            .toList()
        as T;
  }
  if (t == _i1.getType<List<_i27.QueryLogEntry>?>()) {
    return (data != null
            ? (data as List)
                  .map((e) => deserialize<_i27.QueryLogEntry>(e))
                  .toList()
            : null)
        as T;
  }
  if (t == List<_i25.MessageLogEntry>) {
    return (data as List)
            .map((e) => deserialize<_i25.MessageLogEntry>(e))
            .toList()
        as T;
  }
  if (t == _i1.getType<List<_i25.MessageLogEntry>?>()) {
    return (data != null
            ? (data as List)
                  .map((e) => deserialize<_i25.MessageLogEntry>(e))
                  .toList()
            : null)
        as T;
  }
  if (t == List<_i36.SessionLogInfo>) {
    return (data as List)
            .map((e) => deserialize<_i36.SessionLogInfo>(e))
            .toList()
        as T;
  }
  if (t == List<_i38.TableDefinition>) {
    return (data as List)
            .map((e) => deserialize<_i38.TableDefinition>(e))
            .toList()
        as T;
  }
  if (t == List<String>) {
    return (data as List).map((e) => deserialize<String>(e)).toList() as T;
  }
  try {
    return _i3.Protocol().deserialize<T>(data, t);
  } on _i1.DeserializationTypeNotFoundException catch (_) {}
  return super.deserialize<T>(data, t);
}