-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
fromJson cast error with nested Freezed Classes #1118
Comments
I am not sure what I had originally done in my project, but I tried to make it work again and the models are constructed without issue. Perhaps I messed up the syntax. Closing this one. |
A small update: I encountered the issue again: it turned out that it was only a problem that occurred on mobile, and not on web. I was testing on mobile for a while when I encountered this and filed the issue, then I re-implemented it when I was testing on web and I thought it was solved. Then I reverted back to mobile and the issue was back. The root cause turns out to be firebase/flutterfire#11872, where it is written that the response of the cloud function that I use to fetch the required data is different depending on the platform. You don't notice it if you do not have nested classes: you just type However, with nested freezed classes, this conversion is not sufficient, because the nested object will throw the
|
@WesselvanDam see the readme, you need to use
|
@jimmyff a bit late, but the problem was with deserializing, not serializing, so adding 'explicitToJson' would not solve the problem |
Describe the bug
I get the following error:
Because I have a freezed class that has another freezed class as one of its fields, and the generated code does not correctly cast the JSON field of the parent class's fromJSON.
To Reproduce
Simplified code:
The parent class,
UserModel
:child class,
CustomClaimsModel
:Expected behavior
I expect the parent class UserModel to be able to generate an instance of CustomClaimsModel using its
fromJson
method, which should use the CustomClaimsModel'sfromJson
method for the value of the fieldcustomClaims
. If I change all references ofMap<String, dynamic>
in the code of CustomClaimsModel and its generated files toMap
, the code works and I do not get the error. Hence, I suspect that the casting of the JSON to the Map is faulty. Let me know if I'm missing something!The text was updated successfully, but these errors were encountered: