-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Open
Labels
Description
Use Gson
Gson gson = new Gson();
Long a = gson.fromJson("9223372036854775808", Long.class);
System.out.println(a);
=> 9223372036854775807
Use JsonPrimitive
var jp = new JsonPrimitive("9223372036854775808");
Long b = jp.getAsLong();
System.out.println(b);
=> java.lang.NumberFormatException: For input string: "9223372036854775808"
Use Long.valueOf
Long c = Long.valueOf("9223372036854775808");
System.out.println(c);
=> java.lang.NumberFormatException: For input string: "9223372036854775808"
Why is there no error in Gson?
Is this a bug? Or is it a specification?
I want an error to occur.