Skip to content

Freezed keeps ignoring another Freezed class (after renaming) #1332

@busslina

Description

@busslina

So I had working well AuthBarrier. Then I decided to rename it to AuthBarrierLevel, and AuthBarrierResponse which 'depends' on the first, started to complain (Invalid type). I tried to clear cache by removing .dart_tool/ on the package and on the monorepo, and also dart run build_runner clean but I always get the same error:

lib/src/auth_barrier/auth_barrier_response/auth_barrier_response.dart json_serializable                                                                                                 
E Could not generate `fromJson` code for `authBarrierLevel`.                                                                                                                            
  To support the type `InvalidType` you can:                                                                                                                                            
  * Use `JsonConverter`                                                                                                                                                                 
    https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html                                                                                       
  * Use `JsonKey` fields `fromJson` and `toJson`                                                                                                                                        
    https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html                                                                                          
    https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html                                                                                            
  package:auth_lib/src/auth_barrier/auth_barrier_response/auth_barrier_response.freezed.dart:207:26                                                                                     

  207 │  final  AuthBarrierLevel authBarrierLevel;                                                                                                                                      
      │                          ^^^^^^^^^^^^^^^^                                                                                                                                       

AuthBarrierLevel

import 'package:common_lib/lib.dart';
import 'package:data_lib/lib.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'auth_barrier_level.freezed.dart';
part 'auth_barrier_level.g.dart';

// -----------------------------------------------------------------------------
//                  01. Auth barrier level
// -----------------------------------------------------------------------------
@freezed
sealed class AuthBarrierLevel with _$AuthBarrierLevel, AsJson, Serializable {
  const AuthBarrierLevel._();

  /// Allowed.
  factory AuthBarrierLevel.allowed() = AuthBarrierLevelAllowed;

  /// Authenticated.
  factory AuthBarrierLevel.authenticated() = AuthBarrierLevelAuthenticated;

  /// Admin.
  factory AuthBarrierLevel.admin() = AuthBarrierLevelAdmin;

  /// Root.
  factory AuthBarrierLevel.root() = AuthBarrierLevelRoot;

  /// Denied.
  factory AuthBarrierLevel.denied() = AuthBarrierLevelDenied;

  /// Extended.
  factory AuthBarrierLevel.extended({
    required String encodedExtendedAuthBarrierLevel,
  }) = AuthBarrierLevelExtended;

  factory AuthBarrierLevel.fromJson(JsonMap json) =>
      _$AuthBarrierLevelFromJson(json);

  @override
  JsonMap<dynamic> get asJson => toJson();
}

AuthBarrierResponse

import 'package:auth_lib/lib.common.dart';
import 'package:common_lib/lib.dart';
import 'package:data_lib/lib.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'auth_barrier_response.freezed.dart';
part 'auth_barrier_response.g.dart';

// -----------------------------------------------------------------------------
//                  01. Auth barrier response
// -----------------------------------------------------------------------------
@freezed
sealed class AuthBarrierResponse
    with _$AuthBarrierResponse, AsJson, Serializable, Result {
  const AuthBarrierResponse._();

  /// Success.
  factory AuthBarrierResponse.success({
    required AuthBarrierLevel authBarrierLevel,
  }) = AuthBarrierResponseSuccess;

  /// Error.
  factory AuthBarrierResponse.error({required String errorMessage}) =
      AuthBarrierResponseError;

  factory AuthBarrierResponse.fromJson(JsonMap json) =>
      _$AuthBarrierResponseFromJson(json);

  @override
  JsonMap<dynamic> get asJson => toJson();

  @override
  bool get success => this is AuthBarrierResponseSuccess;
}

freezed_annotation: ^3.1.0
json_annotation: ^4.9.0

build_runner: ^2.7.1
freezed: ^3.2.3
json_serializable: ^6.11.1

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions