jankuss / genq

Instant Data Class Generation for Dart
MIT License
133 stars 0 forks source link

JSON deserialization bug: double and int should be deserialized as num #33

Closed BWhiteApps closed 3 months ago

BWhiteApps commented 3 months ago

Some languages will output json for doubles in a format that will break the current way genq is handling doubles and ints.

Ex:

{
     "someDoubleValue": 30.4,
     "anotherDoubleValue": 30,
     "someIntValue": 30,
}

This will break the deserialization when trying to use a double with "anotherDoubleValue".

Instead of generating the following bodyFontSize: json['anotherDoubleValue'] == null ? null : json['anotherDoubleValue'] as double?

Follow JsonSerializableGenerator's lead on this and do (json['anotherDoubleValue'] as num?)?.toDouble()

jankuss commented 3 months ago

Fixed in 0.5.0

brew upgrade jankuss/genq/genq