-
Notifications
You must be signed in to change notification settings - Fork 401
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
genericArgumentFactories: support any variable name for fromJsonT/toJsonT #870
Comments
PRs welcome! 😄 |
I may raise a PR, as the current implementation throws a RangeError if the toJson is defined in an interface (which it will with Freezed) What do you think about simply checking the number of arguments, without checking what they are? This may improve the developer experience too, because the compilation error will show what the problem is. For example at some point I made a mistake in the syntax for "toJson". And instead of |
I don't like guessing. I guess i could just look for one function that matches what is needed here. |
Hello! I have the same warning during code generation. @JsonSerializable(genericArgumentFactories: true, createToJson: false)
class InheritWrapperField<T> {
final T value;
final bool inherit;
InheritWrapperField(this.value, this.inherit);
factory InheritWrapperField.fromJson(
Map<String, dynamic> json, T Function(Object? json) fromJson) =>
_$InheritWrapperFieldFromJson(json, fromJson);
}
If change class name to |
This keeps json_serializable happy, as it checks the name of additional methods provided to the `fromJson` factory[^1]. [^1]: google/json_serializable.dart#870
This keeps json_serializable happy, as it checks the name of additional methods provided to the `fromJson` factory[^1]. [^1]: google/json_serializable.dart#870
Any news on this ? |
Why... Does this matter? It doesn't really affect how you use it, and it keeps to a known, consistent pattern. |
The range error thing is a problem though |
Currently, it appears that
genericArgumentFactories
works only if the mappers use a very specific name formatConsider the following example:
If we renamed
fromJsonFirst
to anything else, then json_serializable would fail with:It would be great if we could use any other variable name instead, such as:
The text was updated successfully, but these errors were encountered: