naveen
naveen

Reputation: 33

jax rs data conversion

I have to return a DTO from service which looks like this:

ResponseDTO
{
  Long id;
  String name;
  //getter and setter etc.
}

Service returns response in json format, and I am using org.codehaus.jackson.jaxrs.JacksonJsonProvider for conversion but at client side when I get response then id value gets changed automatically.

for e.g:- from service side I set value of id as Long.MAX_VALUE but client side json response shows me value "9223372036854776000" which is not the value which I am sending from service.

Am I missing something here?

Upvotes: 1

Views: 290

Answers (1)

mabi
mabi

Reputation: 5306

The thing is that Javascript handles all Numbers as 64-bit IEEE 754 floating point numbers. These can't represent 9223372036854775807 (the value of Long.MAX_VALUE) exactly.

That's the reason why Feature.WRITE_NUMBERS_AS_STRINGS exists. You need to enable this feature to receive the actual number. Note that converting this to a Number will still result in 9223372036854776000 (round up). See this answer for how rounding works in Javascript.

Upvotes: 1

Related Questions