1

I am working with a RESTful API, which serves back data to my ember app in big integer format. For example:

{
    "users":[
        {
            "id":25969533824547743811785852951
        },
        ...
    ]
}

However, Handlebars will display ids in a sort of scientific notation:

2.5969533824547745e+28

So that the link-to route is broken, and the url user/2.5969533824547745e+28/edit will not resolve.

How can I map big integer ids in Ember, so that the IDs are not represented in short-hand or scientific notation?

user1429980
  • 6,872
  • 2
  • 43
  • 53

1 Answers1

3

The easiest solution would be to just send a string. Ember-Data internally uses strings for IDs anyways, so thats the easiest way. The RestAdapter just uses the JSON object passed in from $.Ajax https://github.com/emberjs/data/blob/master/packages/ember-data/lib/adapters/rest_adapter.js#L741 In theory we could implement a custom JSON parser that would first cast ids as string before processing the string but that seems like an overkill and slow. If you cannot change the API that is the method I would look at. Probably just use the returnText from jquery, find/replace all ids as strings and then parseJSON.

node.js is there any proper way to parse JSON with large numbers? (long, bigint, int64) might be helpful

Community
  • 1
  • 1
IgorT
  • 348
  • 1
  • 8