Reputation: 13
Hi I'm trying to read date from a JSON object. Date is written to the JSON as UTC milliseconds, but when I try to read it, informamtion is lost. JSON is giving the number
"time":1526438700000
and
int value = jsonObj.getInt("time")
returns a different value. Could there be information loss converting long
to int
?
I am using the javax.json
implementation. jsonObj
is an object I get from a JsonArray
. I don't think there's a getLong
method. I tried casting to long
, declaring value as long
, same result. I think the problem is getInt()
?
Upvotes: 0
Views: 59
Reputation: 3691
Your number is bigger than the maximum value that could be hold in an int (MAX_VALUE = 2147483647)
Try to get it as a long, as the max value is way bigger (MAX_VALUE = 9223372036854775807L).
With the javax.json library, you can get the long value through getJsonNumber
method
jsonObj.getJsonNumber("time").longValue();
Upvotes: 2