首页 > 其他 > 详细

Gson反射hashmap时数字转变为double的解决方法

时间:2015-05-06 13:26:23      阅读:322      评论:0      收藏:0      [点我收藏+]
import com.google.gson.*

import java.lang.reflect.Type

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


Gson反射hashmap时数字转变为double的解决方法

原文:http://my.oschina.net/sphl520/blog/411236

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!