charafau / json2builtvalue

Json to Dart built_value classes generator
Apache License 2.0
153 stars 24 forks source link

Exception raised when parsing null values or empty lists. #3

Open SocratesDz opened 6 years ago

SocratesDz commented 6 years ago

After trying to parse some json strings with https://charafau.github.io/json2builtvalue/, it throws a RangeError exception when trying to parse empty lists and null values, e.g.:

{ "a": 1, "b": 2, "c": [], "d": null }

Wouldn't it be better if you return dynamic types in this cases?

charafau commented 6 years ago

thanks for comment. To be honest I'm not sure what would be the best case to support this case, the point of model class is to have strong type (now even more with dart2). In my opinion generator should show error when json is not valid.

SocratesDz commented 6 years ago

I understand, at first I was wondering what datatype you should return. But as the null value is unknown, I guess dynamic would fit better.

charafau commented 5 years ago

Sorry for wrong response, I usually don't put nulls in json so it takes me long to fix those. As for me it should probably skip that if someone put 'null' in json

SocratesDz commented 5 years ago

I see it fit, if there's null, you could skip it.