I'm supposed to receive long integer in my web service.
long ipInt = (long) obj.get("ipInt");
When I test my program and put ipInt value = 2886872928, it give me success. However, when I test my program and put ipInt value = 167844168, it give me error :
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
The error is point to the above code.
FYI, my data is in JSON format :
{
"uuID": "user001",
"ipInt": 16744168,
"latiTude": 0,
"longiTude": 0,
}
Is there any suggestion so that I can ensure my code able to receive both ipInteger value?
obj
? How is it created and populated? – Commensalint
value try usingLong.parseLong(int)
– Fatherhoodobj.get("ipInt")
apparently returnsInteger
, I can't see how that would work. – Scevorlong
, which would solve your issue altogether. Here is a solution for jackson (if that's what you're using) – Epigraphy