hiranthaR / Json-to-Dart-Model

Json to Dart Model extension can convert JSON objects into Dart data classes. It supports pure Dart class conversion, Flutter-recommended JSON serialization using annotations, Freezed support, Effective Dart:Style, and many more features. Currently, it has more than 135,000 installs.
https://marketplace.visualstudio.com/items?itemName=hirantha.json-to-dart
MIT License
93 stars 18 forks source link

number cast to int not double #78

Closed jinjilynn closed 2 years ago

jinjilynn commented 2 years ago
{
     "totalManPrice": 0.0,
}

for example, i have a json snippet, and when i use command 'From Clipboard to Code Generation Classes', I get the result of

   totalManHour: json['totalManHour'] as int?,

is there some config to default num type as double?

iamarnas commented 2 years ago

@jinjilynn Hi 👋 Thank you for reporting.

This is known issue becouse 0.0 is equal to 0 and TypeScript read it as double and integer. Generator just prefer integer in this situation. To get double you need just correct to double as in the example below 👇

{
     "totalManPrice": 0.1
}

I will try to fix it when I I'll have free time.

jinjilynn commented 2 years ago

@jinjilynn Hi 👋 Thank you for reporting.

This is known issue becouse 0.0 is equal to 0 and TypeScript read it as double and integer. Generator just prefer integer in this situation. To get double you need just correct to double as in the example below 👇

{
     "totalManPrice": 0.1
}

I will try to fix it when I I'll have free time.

ok,thank you