Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no Integer in javascript, fixed Json
- Loading branch information
Showing
4 changed files
with
5 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that JSON only defines a "Number" but it's pretty annoying to send entity IDs as 9324.0. Do you have any suggestions to make APIs a little nicer, without all the unnecessary decimal points?
Why would it be a problem to keep the Integer serialization the way it was? Both would be valid JSON: 1 and 1.0.
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely agree with @ikester. In my experience non-js json libraries tend to treat numbers as two distinct types. For example python's json library deserializes json numbers into ints and floats.
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadek, do you feel very strongly about this? How could it be harmful to have these additional Integer Writes?
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can't introduce JsInteger. It doesn't make sense at all. 9324.0 is as valid as 9324 in json since it has a single number type. And anyway since we switched to BigDecimal for the internal representation, this pseudo issue is now solved.
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it is technically valid, but it's not very practical (or pretty) when you're trying to pass around numeric IDs, like primary keys (e.g. { id: 1243.0, name: "Some Name"}. I don't recall seeing any REST APIs that return integers like this.
I didn't understand what you meant by the BigDecimal pseudo issue.
I guess my real question is: why is it bad if we leave it in? Does it break something?
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that your issue should be fixed now. Writing 1243.0 as 1243 was just a printing issue. No need to introduce a new type in the user API for that.
7f7c953
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh OK. I had missed that point. I just tested it and it printed the integer without decimals.
Thanks!