json2builtvalue icon indicating copy to clipboard operation
json2builtvalue copied to clipboard

Exception raised when parsing null values or empty lists.

Open SocratesDz opened this issue 6 years ago • 4 comments

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?

SocratesDz avatar Aug 05 '18 00:08 SocratesDz

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.

charafau avatar Aug 13 '18 22:08 charafau

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.

SocratesDz avatar Aug 14 '18 00:08 SocratesDz

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

charafau avatar Oct 02 '18 00:10 charafau

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

SocratesDz avatar Oct 03 '18 16:10 SocratesDz