Skip to content

TypeAdapterFactory INTEGER_FACTORY will change INTEGER type to LONG type #2680

@L-Ymeng

Description

@L-Ymeng

Gson version

2.10.1

Java / Android version

21

Description

I try to get a JsonElement by toJsonTree method. but i found that when i use integer object as input, i will get a long object with method JsonElement.getAsNumber()

I think this commit caused this problem:3e3266c

Is this a bug or a feature?

Expected behavior

use integer type as input, get integer type as output

Actual behavior

use integer type as input, get long type as output

Reproduction steps

    @Test
    public void test(){
        Integer testNum = 1;
        JsonElement jsonTree = new Gson().toJsonTree(testNum);
        System.out.println(jsonTree.getAsNumber().getClass());
    }

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