Skip to content

Long upper limit value #1727

@lissxxxx

Description

@lissxxxx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions