Javascript Long Integer

    Table of contents

Javascript long integer

Tags: javascript , java , json , spring , integer Answers: 1 | Viewed 107,812 times



I have seen one of the weirdest things in javascript.
The server side (spring):


   @RequestMapping(value = "/foo", method = RequestMethod.GET)
@ResponseBody
public Long foo() {
return 793548328091516928L;
}

I return a single long value and:


$.get('/foo').done(function(data){
console.log(data);
});

It represents the long integer as "793548328091516900" replacing (rounding indeed) the last two digits with 0s. When i make that GET request from any browser's address bar, the number represented correctly; thus this is a js issue, in my opinion.


Returning a string instead of long from server and handling it with:


var x = new Number(data).toFixed();

obviously a solution. But I am not so lucky that, I have to handle a complex POJO (converted to JSON) whose some fields (some are nested) are typed with java.lang.Long type. If i try to cast this POJO to another object does not having fields typed Long, it is obviously cumbersome.


Is there any solution to that obstacle in a clearer way?


Some Answers For Javascript Long Integer

Please leave your answer here: