Skip to content
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

Getting a null error when converting from Firebase a complex object, how to debug? #1328

Closed
giorgio79 opened this issue Jun 11, 2023 · 4 comments

Comments

@giorgio79
Copy link

Hello,

I have a complex object and when reading from Firebase, I started getting this error
type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast

Its quite cryptic, no error line in the object_g.dart file, or the actual propert name. How could I debug this? (without printing each item one by one?)

@rorystephenson
Copy link

I've got a similar issue. I guess it's not really Firebase specific, it's an issue whenever you have nested json objects and deserialisation fails because a non-nullable field is null. Ideally there would be an indication of what field was missing and where in the json structure the missing field was expected.

I suppose this can be somewhat improved by manually wrapping each nested objects fromJson in a try/catch but you still won't know which field was missing and in my case the model classes are generated automatically so adding the try/catch statements is not possible without a change to the model generator.

@walid-ashik
Copy link

is there any update on this? still seems like it's huge burden to work with a large object

@kevmoo
Copy link
Collaborator

kevmoo commented Nov 29, 2024

You can always use checked mode to help here! Just keep in mind it adds quite a bit of runtime overhead.

https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/checked.html

@kevmoo kevmoo closed this as completed Nov 29, 2024
@kevmoo
Copy link
Collaborator

kevmoo commented Nov 29, 2024

Also, keep in mind using a debugger can be helpful here, too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants