How to avoid rounding long value on the client side?

Using a playback platform.

controller

@BodyParser.Of(BodyParser.Json.class) public static Result getResponseJson(Long id){ List<DataField> entities = new Model.Finder<>(Long.class, DataField.class) .where("response_id = " + id).findList(); Response response = new Response(entities, id); return ok(toJson(response)); } 

Response Object:

 public class Response { private Long uuid; private Map<TableField, String> map = new HashMap<>(); ...constructors, getters and setters... } 

I am checking the response using POSTMAN. On the "Raw" tab, I got:

 {"uuid":3942015886343226874,"map":{"Work":"Contract","locale":"Mogilev"}} 

On the "Pretty" tab:

 { "uuid": 3942015886343227000, "map": { "Work": "Contract", "locale": "Mogilev" } } 

Why is uuid rounded up?

+5
source share
1 answer

This is not related to Playframework, this is a problem with the browser. Open the developer console in your browser and try this -

 var c = 3942015886343226874; console.log(c); 

This will print - 3942015886343227000

due to the number limit in javascript.

Better to use String in case of UUID.

+2
source

All Articles