Json-to-Dart-Model icon indicating copy to clipboard operation
Json-to-Dart-Model copied to clipboard

Make 0.0 as double not int when assigning it as a default value

Open globalwebforce opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

I have a rating property which has a default value of 0, but can have a value of 0.5, 2.4 etc.

{
  "d@rating": 0.00,
}

Expected Behavior

I was expecting to have a double but instead I received an int

@Default(0) int rating, //this must be double

Steps To Reproduce

No response

Version

No response

Relevant JSON syntax

No response

Anything else?

No response

globalwebforce avatar Jun 08 '22 05:06 globalwebforce

@globalwebforce Hi.

I have tried to fix it a long time ago. But problem is that TypeScript calculate 0.0 as 0 becouse in reality is 0 for both double and integer. That why generator can't detect 0.0 as double becouse typescript always return 0. In your case you should write 0.01 as default and later correct in your code to 0.0 it is quick fix. And this issue describes in the documentation.

For example you can try another generator like QuickType and you will get same result.

iamarnas avatar Jun 08 '22 06:06 iamarnas