-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generics complicate self-referential class structure #1415
Comments
I have same problem :c |
class BaseConverter<T> extends JsonConverter<Base, Map<String, Object?>> { What happens if you write Writing just That said, I won't be surprised if that doesn't fix it. Here's a possibly related issue: which suggests that the logic for applying a JsonConverter doesn't currently do everything one would hope it would when there are type parameters involved. |
@craiglabenz – is this what you want? diff --git a/json_serializable/test/generic_files/for_craig.dart b/json_serializable/test/generic_files/for_craig.dart
index 5555d80..bb0011e 100644
--- a/json_serializable/test/generic_files/for_craig.dart
+++ b/json_serializable/test/generic_files/for_craig.dart
@@ -6,12 +6,12 @@ class Base<T> {
const Base();
}
-class BaseConverter<T> extends JsonConverter<Base, Map<String, Object?>> {
+class BaseConverter<T> extends JsonConverter<Base<T>, Map<String, Object?>> {
const BaseConverter();
@override
Map<String, Object?> toJson(Base object) => {};
@override
- Base fromJson(Map<String, Object?> json) => const Base();
+ Base<T> fromJson(Map<String, Object?> json) => Base<T>();
}
@JsonSerializable()
@@ -26,8 +26,7 @@ class Data<T> extends Base<T> {
final String name;
@BaseConverter()
- // Ideally, this would be Base<T>, but defining it so breaks the build
- final Base data;
+ final Base<T> data;
Map<String, dynamic> toJson() => _$DataToJson(this);
} And instantiate |
Looks right, @kevmoo |
The following code builds, but see the comment for which critical information has to be removed for said build to succeed:
Changing
final Base data
tofinal Base<T> data
results in this error:This despite the fact that a
JsonConverter
is clearly being used.For posterity, I originally reported this at rrousselGit/freezed#1074, and was (correctly, it seems) directed here.
The text was updated successfully, but these errors were encountered: