HypixelDev / PublicAPI

Official Java implementation of the Hypixel Public API.
https://api.hypixel.net
MIT License
535 stars 152 forks source link

Guild parsing fails on too large experience #536

Closed Rigner closed 1 year ago

Rigner commented 2 years ago

Hey,

I noticed a parsing error when fetching the guild for a user, because the experience amount was too large and was encoding as a double instead of a long: "1.6434933249E12".

The field just needs to be changed from a long to a double.

Can be reproduced here: https://api.hypixel.net/guild?key=KEY&player=9d7eccf5-2a1e-419f-9864-312c22208f07

Rigner commented 2 years ago

https://api.hypixel.net/guild?key=KEY&player=bcdb84f3-5534-4c7e-9d61-cc1829670ec4

Just saw another case, where timestamps are also doubles.

Rigner commented 1 year ago

Bumping this to get the PR merged, still an issue (I'm using a fork version anyways, but yeah would be cool to fix here too).

Rigner commented 1 year ago

This issue is still occuring, like I said it must be a double and not a long.

ConnorLinfoot commented 1 year ago

I'm pretty sure they are never doubles, do you have an example of one with a double? The example given in the original post is a long, just in a scientific notation

Rigner commented 1 year ago

Indeed it's scientific notation, but iirc I was seeing issues with Gson failing to parse it back to a long. Will test again when I can

mdashlw commented 1 year ago

You can't parse scientific notation into long

jshell> Long.parseLong("1.6434933249E12")
|  Exception java.lang.NumberFormatException: For input string: "1.6434933249E12"
|        at NumberFormatException.forInputString (NumberFormatException.java:67)
|        at Long.parseLong (Long.java:708)
|        at Long.parseLong (Long.java:831)
|        at (#1:1)

jshell> Double.parseDouble("1.6434933249E12")
$2 ==> 1.6434933249E12

The solution might be to not serialize them as scientific notation in the first place, if it's the API service doing it