0

If I try to get an JSON response from a backend I wrote I get following response which is completely correct:

{
  "status": "ok",
  "get": {
    "5b7e4b0b-fc98-4107-ab72-32577440e02e": {
      "isUser": false,
      "permissions": {
        "play": true,
        "disconnect": true,
        "debug": false,
        "color": false,
        "leaderboard-collect-voice": true,
        "view-bot-log": false,
        "command-boobs": false,
        "embed-builder": false,
        "clear": false,
        "admin": false,
        "skip": true,
        "w2g": true,
        "pause": true,
        "clear-queue": true,
        "leaderboard": true,
        "rank-self": true,
        "rank-other": true,
        "leaderboard-collect-text": true,
        "queue": true,
        "move-to-me": false
      },
      "id": 0
    },
    "d902f18f-95ad-432c-9ee9-27e63ff6fce1": {
      "isUser": false,
      "permissions": {
        "play": false,
        "disconnect": false,
        "debug": false,
        "color": false,
        "leaderboard-collect-voice": false,
        "view-bot-log": false,
        "command-boobs": true,
        "embed-builder": false,
        "clear": false,
        "admin": false,
        "skip": false,
        "w2g": false,
        "pause": false,
        "clear-queue": false,
        "leaderboard": false,
        "rank-self": false,
        "rank-other": false,
        "leaderboard-collect-text": false,
        "queue": false,
        "move-to-me": false
      },
      "id": 767965825293746217
    }
  }
}

But it seems if Chrome tries to get the data it gets in the response from the server the correct data but in the preview and the JavaScript of the site gets an wrong value. I tried to change the value but nothing works. It seems that every time the last 2 digits are replaced by zeros.

correct value

wrong value

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 1
    did you store the id as a number?? try to store the id as a string – sonEtLumiere Oct 20 '20 at 04:48
  • @sonEtLumiere my problem is the json is generated by GSON and i dont know how to tell GSON to store longs as strings. Im allready at looking but i dont find anything about that. And should js not use int64? So it should not be a problem to get a long as an int. –  Oct 20 '20 at 04:54
  • Uh i think i found something: https://stackoverflow.com/questions/48104306/java-gson-serialize-int-as-strings-to-json-file –  Oct 20 '20 at 04:57
  • 1
    Sure? That's how the JavaScript number type works. It can only model integers up to 2^53 - 1 which your `id` is _well_ above. See [isSafeInteger()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger) and friends for more details on the limitations of the Number datatype. – Mike 'Pomax' Kamermans Oct 20 '20 at 05:07

1 Answers1

2

It has to do with how javascript is handling numbers. Even stored in a long, your number is still "too big" and can't be represented as a Javascript number. You'd be better off storing it as a string.

Check out this Stackoverflow subject for more details. Some people brought up alternative solutions.

Henry Mont
  • 337
  • 1
  • 3
  • 13