google / json_serializable.dart

Generates utilities to aid in serializing to/from JSON.
https://pub.dev/packages/json_serializable
BSD 3-Clause "New" or "Revised" License
1.55k stars 395 forks source link

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

Open giorgio79 opened 1 year ago

giorgio79 commented 1 year ago

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 commented 11 months ago

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.