android Gson 默认double 转 int

Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").registerTypeAdapter(Double.class, new JsonSerializer<Double>() {

    @Override
    public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) {
        if (src == src.longValue())
            return new JsonPrimitive(src.longValue());
        return new JsonPrimitive(src);
    }
}).create();

 

posted @ 2019-09-17 14:02  cxf2018  阅读(455)  评论(0编辑  收藏  举报