解決gson解析long自動轉為科學計數的問題


不廢話,直接上代碼:

public class GsonUtils {
    public static Gson getMapGson(){
        Gson gson=new GsonBuilder().registerTypeAdapter(Map.class, new JsonDeserializer<Map>() {
            public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                    throws JsonParseException{
                HashMap<String,Object> resultMap=new HashMap<>();
                JsonObject jsonObject = json.getAsJsonObject();
                Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
                for (Map.Entry<String, JsonElement> entry : entrySet) {
                    resultMap.put(entry.getKey(),entry.getValue());
                }
                return resultMap;
            }
        }).create();
        return gson;
    }
}

使用方式

Gson gson = GsonUtils.getMapGson();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM