How to prevent Gson from converting a long number (a json string ) to scientific notation format?

前端 未结 7 2164
予麋鹿
予麋鹿 2020-11-29 06:14

I need to convert json string to java object and display it as a long. The json string is a fixed array of long numbers:

{numbers
[ 268627104, 485677888, 506         


        
7条回答
  •  既然无缘
    2020-11-29 06:24

    If serializing to a String is an option for you, you can configure GSON to do so with:

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setLongSerializationPolicy( LongSerializationPolicy.STRING );
    Gson gson = gsonBuilder.create();
    

    This will produce something like:

    {numbers : [ "268627104", "485677888", "506884800" ] }
    

提交回复
热议问题